任何人都可以點我怎麼POST JSON的工作示例,以一個RESTful API(例如網頁API)使用的Windows Phone 8?我有一個GET的工作示例,但似乎無法找到POST的任何工作示例。所有的POST的例子,我已經找到了C#不上的Windows Phone 8(由於剝離下來的.NET framework)工作。如何發佈到REST風格的API隨着Windows Phone 8
回答
好吧,我終於能拿出一個可行的解決方案,所以我想將它張貼回來的完整性。但是,如果有人知道在Windows Phone 8中執行此操作的更好方法,我很樂意看到它!
public void SendPost(Uri uri, string json)
{
var webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
webClient.UploadStringCompleted += this.sendPostCompleted;
webClient.UploadStringAsync(uri, "POST", json);
}
private void sendPostCompleted(object sender, UploadStringCompletedEventArgs e)
{
// Handle result
Console.WriteLine("HTTP POST Result: {0}", e.Result);
}
如何帖子ID =「XYZ」和密碼=「123」作爲參數同時調用Restful WebServices?請幫我 –
Web客戶端是不是在Windows Phone 8.1框架的類無效。 –
@RahulSaksule,看http://stackoverflow.com/a/5401597/1948785傳遞參數 – eeadev
要做到這一點是使用Restsharp的最佳方式:
Dim client As New RestSharp.RestClient("https://stuff.com/api/") Dim req As New RestSharp.RestRequest("dothings", Method.POST) req.RequestFormat = DataFormat.Json req.AddBody(New reqAuth With {.param1 = "stuff1", .param2= "stuff2"}) client.ExecuteAsync(req, Sub(res) Console.WriteLine(res.Content) End Sub)
public async void makeRequest(String resourceUri)
{
HttpClient httpClient = new HttpClient();
try
{
HttpResponseMessage response = await httpClient.GetAsync(resourceUri);
}
catch (HttpRequestException hre)
{
Console.Write(hre.Message);
}
catch (TaskCanceledException)
{
}
}
記得添加的NuGet包:HttpClient的
這並沒有提供詳細的解釋如何爲Windows Phone 8的執行POST操作。 –
string email = txtEmailAddress.Text;
string password = txtPassword.Text;
string confirmPassword = txtConfirmPassword.Text;
string dd = txtDD.Text;
string mm = txtMM.Text;
string yyyy = txtYYYY.Text;
UserDetails ud = new UserDetails
{
DateofBirth = DateTime.Now.ToString(),
EmailAddress=email,
Password=password,
ProfileImage="",
UserID="0"
};
WebClient wc = new WebClient();
wc.Headers["Content-Type"] = "application/json";
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer serializertoUpload = new DataContractJsonSerializer(typeof(UserDetails));
serializertoUpload.WriteObject(ms, ud);
string data = Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length);
wc.UploadStringAsync(new Uri("<wcfserviceurl>"), "POST", data);
這裏的UserDetails類的定義
public class UserDetails
{
public string UserID { get; set; }
public string EmailAddress { get; set; }
public string Password { get; set; }
public string DateofBirth { get; set; }
public string ProfileImage { get; set; }
}
- 1. Windows Phone 8風格
- 2. REST風格的Web服務發佈API
- 3. sqlite的隨着Windows Phone 8的應用開發
- 4. skydrive api windows phone 8
- 5. 如何將圖像從Windows Phone 8發佈到PHP
- 6. 如何使用jQuery AJAX發佈到REST風格的Web服務?
- 7. VoIP的API - 的Windows Phone 8
- 8. 的Windows Phone 8 - Twitter的API
- 9. Windows Phone 8開發
- 10. 風格的Windows Phone 7
- 11. 如何發揮。FLV文件的Windows Phone 7或Windows Phone 8
- 12. 如何構建REST風格的API
- 13. 如何使用REST風格的API
- 14. 點擊事件不會隨着Windows Phone 8
- 15. 如何通過Windows Phone 8中的HTTPS發佈請求登錄?
- 16. 如何從Windows Phone 8的發佈到Asp.Net MVC4的WebAPI,並得到JSON回來
- 17. windows phone 8.1 call rest api c#
- 18. 如何從Mule Flow發佈到REST API?
- 19. Windows Phone 8全景佈局
- 20. REST風格的Windows電話
- 21. REST風格的API和rails
- 22. REST風格的API架構
- 23. Symfony2 REST風格的API + AngularJS
- 24. 的風格通過REST API
- 25. REST風格的API設計
- 26. REST風格的API和Userfrosting
- 27. 從windows phone到windows 8
- 28. 寶REST API隨着RestSharp不xamarin的Android
- 29. Windows Phone 8功能到Windows Phone 7
- 30. 將Windows Phone 7.5升級到Windows Phone 8?
這可能是有益的: 我們http://stackoverflow.com/questions/14698879/http-post-for-windows-phone-8 – anderZubi