Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中执行以下curl命令_Java_Url_Curl_Urlconnection - Fatal编程技术网

如何在Java中执行以下curl命令

如何在Java中执行以下curl命令,java,url,curl,urlconnection,Java,Url,Curl,Urlconnection,如何在JavaURLConnection中实现下面的curl命令 curl -X PUT \ -H "X-Parse-Application-Id: " \ -H "X-Parse-REST-API-Key: " \ -H "Content-Type: application/json" \ -d '{"score":73453}' 提前感谢使用其派生类,您可以轻松完成此操作 URL myURL = new URL(serviceURL); HttpURLConnection

如何在JavaURLConnection中实现下面的curl命令

curl -X PUT \
  -H "X-Parse-Application-Id: " \
  -H "X-Parse-REST-API-Key: " \
  -H "Content-Type: application/json" \
  -d '{"score":73453}'

提前感谢

使用其派生类,您可以轻松完成此操作

URL myURL = new URL(serviceURL);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
myURLConnection.setRequestMethod("PUT");
myURLConnection.setRequestProperty("X-Parse-Application-Id", "");
myURLConnection.setRequestProperty("X-Parse-REST-API-Key", "");
myURLConnection.setRequestProperty("Content-Type", "application/json");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);
myURLConnection.connect();

JSONObject jsonParam = new JSONObject();
jsonParam.put("score", "73453");

OutputStream os = myURLConnection.getOutputStream();
os.write(URLEncoder.encode(jsonParam.toString(),"UTF-8"));
os.close();
对于
curl-X GET \-H“X-Parse-Application-Id:“\-H”X-Parse-REST-API-Key:“\-G \-data urlencode”include=game

String charset = "UTF-8";
String query = String.format("include=%s", URLEncoder.encode("game", charset));
URL myURL = new URL(serviceURL+"?"+query);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
myURLConnection.setRequestMethod("GET");
myURLConnection.setRequestProperty("X-Parse-Application-Id", "");
myURLConnection.setRequestProperty("X-Parse-REST-API-Key", "");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);
myURLConnection.connect();

curl命令在哪里?curl-X PUT \-H“X-Parse-Application-Id:“\-H”X-Parse-REST-API-Key:“\-H”内容类型:Application/json“\-d'{”score:73453}“\n您可以使用http客户端api和方法设置这些标题感谢您的回复我收到以下服务器返回的http响应代码:400 for URL:@user3130151我的错,这是因为我使用了单引号而不是双引号。告诉我它现在是否工作?@user3130151刚刚使用JSONObjet和URLEncoder再次更新了它这次你很可能没有400个响应代码
:-)
Khaled这太神奇了:D