【发布时间】:2014-12-04 21:52:08
【问题描述】:
我是 Windows Phone 新手。我有一个假期对象,我想在我的数据库中更新它。 我使用 Spring 作为 REST API,并且我有一个方法:
@RequestMapping(value="/vacation", method = RequestMethod.PUT, consumes ="application/json")
public void updateVacation(@RequestBody Vacation vacation){
new VacationDao().update(vacation);
}
在我的 Windows Phone 应用程序中,我有以下 put 方法:
public async void PushSubscription(Subscription subscription)
{
try
{
var httpWebRequest = (HttpWebRequest) WebRequest.Create(apiUrl);
httpWebRequest.ContentType = "text/plain; charset=utf-8";
httpWebRequest.Method = "PUT";
// Write the request Asynchronously
using (var stream = await Task.Factory.FromAsync<Stream>(httpWebRequest.BeginGetRequestStream,
httpWebRequest.EndGetRequestStream, null))
{
//create some json string
string json = JsonConvert.SerializeObject(subscription);
// convert json to byte array
byte[] jsonAsBytes = Encoding.UTF8.GetBytes(json);
// Write the bytes to the stream
await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);
MessageBox.Show("Ik geraak hier");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我没有任何异常,我确定我在我的 WP 客户端中传递代码,但我无法在服务器上传递代码...
有什么帮助吗?
【问题讨论】:
标签: c# spring rest windows-phone-8 put