【发布时间】:2015-05-17 00:44:22
【问题描述】:
我正在尝试将 json 对象从 java 客户端发送到 C# WebApi,但输入参数为空。 java代码:
ObjectMapper mapper = new ObjectMapper();
Gson gson = new Gson();
String json = gson.toJson(per);
HttpClient httpclient = new DefaultHttpClient();
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("person", json.toString()));
HttpGet httpPost = new HttpGet("http://naviserver.azurewebsites.net/api/Person/Get?" + URLEncodedUtils.format(qparams, "UTF-8"));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader(
"Authorization",
"Bearer TokenRemovedBecauseUseless");
org.apache.http.HttpResponse httpResponse = httpclient.execute(httpPost);
WebApi 方法:
public List<String> Get([FromUri]Person person)
{}
谁能告诉我如何发送 json 对象?
【问题讨论】:
标签: java c# android json asp.net-web-api