1
這裏是我的捲曲請求,這工作完全正常失敗。捲曲的作品,但相應的HttpConnection POST請求的400錯誤
curl -X POST http://build-master-mobile.xxx.com:8080/job/Reprovision-IPA/build --data-urlencode json ='{「parameter」:[{「name」:「IPA_URL」,「value」:「xxx」},{「name」:「IPA_FILENAME」,, 「值」:「xxx.ipa」}]}」
現在我試圖使用HttpConnection的,如下圖所示,從我的Java代碼做這個職位,但它給了我400錯誤的請求。 請專家幫我解決這個問題。
URL url = new URL("http://build-master-mobile.xxx.com:8080/job/Reprovision-IPA/build");
URLConnection urlConnection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection)urlConnection;
httpConn.setRequestProperty("Accept", "application/json");
httpConn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
httpConn.setRequestProperty("Connection", "keep-alive");
httpConn.setRequestMethod("POST");
String data = "{\"parameter\":[{\"name\":\"IPA_URL\",\"value\":\"xxx\"},{\"name\":\"IPA_FILENAME\",\"value\":\"xxx.ipa\"}]}";
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
// send request
OutputStreamWriter wr = new OutputStreamWriter(httpConn.getOutputStream());
wr.write(data.toString());
wr.flush();
wr.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
你似乎已經忘了'JSON ='起步。 – immibis
我試着用json =在開始時也是如此,但同樣的400錯誤。字符串數據= 「JSON ='{\ 」參數\「:[{\ 」名稱\「:\ 」IPA_URL \「,\ 」值\「:\ 」一\「},{\ 」名稱\「:\」 IPA_FILENAME \」,\ 「值\」:\ 「a.ipa \」}]}'「; – dev123
謝謝immibis!此外,我錯過了正確的contentType是「application/x-www-form-urlencoded」,它現在可以工作。謝謝謝謝!! – dev123