0
我收到錯誤org.apache.http.client.HttpResponseException:錯誤的請求,當我嘗試運行此程序。org.apache.http.client.HttpResponseException:錯誤的請求 - 通過REST發送JSON請求
你能幫我理解我應該修改代碼嗎?
我使用下列庫 的HttpClient-4.4.1.jar 的HttpCore-4.4.1.jar 共享記錄-1.1.2.jar
org.apache.http.client.HttpResponseException:錯誤的請求
下面是代碼:
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
public class Test {
public static void main(String args[]) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://localhost:8080/engine-rest/process-definition/key/demo-scaling/start");
try {
StringEntity input = new StringEntity("(\"variables\":{}, \"businessKey\" : \"AAA001\")");
postRequest.addHeader("Accept", "application/json");
postRequest.setEntity(input);
postRequest.addHeader("Content-Type", "application/json");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(postRequest, responseHandler);
System.out.println(responseBody);
} catch (Exception e) {
e.printStackTrace();
} finally {
httpclient.getConnectionManager().shutdown();
}
}
}
「http:// localhost:8080/engine-rest/process-definition/key/demo- scaling/start」爲什麼在縮放/啓動之前你有空格?如果您需要空格,請使用%20。那麼你將有一個有效的網址和正確的請求:) – Hrabosch
我有它正確的程序Hrabosch我剛剛檢查它。 – Adam
好吧,那麼你可以嘗試例如郵編擴展爲Chrome和嘗試手動呼叫我。 – Hrabosch