帮我将json数据从Android发布到Asp.net 这是下面的代码。 Android将json数据发送到webapi
公共类UploadByTableActivity扩展了活动{
final static String url = "https://webapi.com/api/post/";
HttpResponse response;
AsyncHttpClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uploadbytable);
Button btnWO = (Button) findViewById(R.id.btnwo);
btnWorkOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
JSONObject jsonParams = new JSONObject();
String username = "id";
String password = "pw";
client = new AsyncHttpClient(true, 80, 443);
client.addHeader(
"Authorization",
"Basic " + Base64.encodeToString(
(username + ":"+ password).getBytes(),Base64.NO_WRAP)
);
client.setEnableRedirects(true);
RequestParams params = new RequestParams();
// params.put("file", new File(pathoffile));
params.put("name", "name1");
params.put("phone", "111-111-1111");
StringEntity entity = null;
try {
entity = new StringEntity(params.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
client.post(null,url,entity, "application/json", new AsyncHttpResponseHandler(Looper.getMainLooper()) {
@Override
public void onSuccess(int i, Header[] headers, byte[] bytes) {
Log.i("appTag", "OK");
}
@Override
public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
Log.i("appTag"," Error = " + throwable.getMessage());
}
});
}
});
}
尝试从webapi到asp.net检索jsondata,但jsonString为null。 请帮助我如何获取json数据。
[HttpPost]
public string post([FromBody]string jsonString){
return jsonString;
}