HTTP/1.1 500 Server Error

我用CloseableHttpAsyncClient这个做post请求,但是服务器返回500错误, 这个错误是因为contentType设置不对导致的, 我参数的格式为a=b&c=d&e=f是这用格式的, 所以,contentType需要设置为: application/x-www-form-urlencoded 就好了;

部分代码:

String sign = "MERCHANTID="+merchant_id+"&ORDERNO="+order_no+"&ORD
String content = "merchantId="+merchant_id+"&barcode="+barcode+"&o
StringEntity postEntity = new StringEntity(content);
postEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(postEntity);
//httpPost.setHeader("content-type","application/json");
Future future = httpclient.execute(httpPost, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");

你可能感兴趣的:(Java)