通过Web客户端上传JSON [英] Upload JSON via WebClient

查看:181
本文介绍了通过Web客户端上传JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序使用jQuery来与我的后端进行交互。后端成功接受JSON数据。举例来说,我可以成功发送下列JSON:

I have a web app with that is using JQuery to interact with my backend. The backend successfully accepts JSON data. For instance, I can successfully send the following JSON:

{ "id":1, "firstName":"John", "lastName":"Smith" }

我现在有一个Windows Phone应用程序必须打这个后端。我需要通过Web客户端通过同样的JSON。目前,我有以下的,但我不知道如何真正通过JSON。

I now have a Windows Phone app that must hit this backend. I need to pass this same JSON via a WebClient. Currently I have the following, but i'm not sure how to actually pass the JSON.

string address = "http://www.mydomain.com/myEndpoint;
WebClient myService = new WebClient();
utilityService.UploadStringCompleted += new UploadStringCompletedEventHandler(utilityService_UploadStringCompleted);
utilityService.UploadStringAsync(address, string.Empty);

谁能告诉我什么,我需要做什么?

Can someone tell me what I need to do?

推荐答案

想通了。我忘记了以下内容:

Figured it out. I was forgetting the following:

myService.Headers.Add("Content-Type", "application/json");

这篇关于通过Web客户端上传JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆