2017-11-16 20 views
0

httpリクエストをサーバーに投稿したいと思います。私はJavaでJsoupを使用します。サーバーにhttpリクエスト(xmlデータ)を投稿する方法

以下は、Charles Proxyで取得したサンプルの生データです。

誰でもJSoupでhttp投稿形式を構築するのに役立ちますか?

データは次のようにxml形式です。

POST /servlet/PracticeGameServlet?slotId=4785973322575773697&userId=1809015101&gameName=farm_queen&slotType=light HTTP/1.1 
Host: www.luogames.com 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0 
Accept: application/xml, text/xml, */*; q=0.01 
Accept-Language: en-US,en;q=0.5 
Accept-Encoding: gzip, deflate 
Content-Type: text/xml; charset=UTF-8 
X-Requested-With: XMLHttpRequest 
Referer: http://www.luogames.com/games/puzzle-games/farm-queen/?action=play&templateId=9907&accepted=true 
Content-Length: 858 
Cookie: combo=pref_lang=en_US:partner=midas:user=g_gabr:country=US:type=0:operator=0:version=3.0:userId=1809015109:checksum=a2b4276039dda3324aeb2e75451c7e6c; __utma=141518769.969069584.1510752477.1510800193.1510802396.4; __utmz=141518769.1510752477.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=141518769.|1=partner=midas=1^2=userType=practice_player=1^3=isVIP=false=1; OU812=6; JSESSIONID=hdkaOGaixpzxmf1nV1c-v; BIGipServercfgsync~p_www.royalgames.com=2115312300.20480.0000; __utmb=141518769.8.9.1510802547163; __utmc=141518769; __utmt=1; l_inst=web170; ver_usr=1809015101_1118652028; midas_test=test 
Connection: keep-alive 

<?xml version="1.0" encoding="UTF-8" ?> 
<client action="gameover" slotId="4785973322575773697" playId="0" request="3" magic="1707974221"> 
<gameover time="2017-11-15 19:23:16" lastplaydataid="8"> 
<result><![CDATA[2000]]></result> 
<entry id="1" time="2017-11-15 19:22:45"><![CDATA[113|0|0|2000|0]]></entry> 
<entry id="2" time="2017-11-15 19:23:07"><![CDATA[111|664|20|0|0|potato]]></entry> 
<entry id="3" time="2017-11-15 19:23:07"><![CDATA[112|664|0|0|0]]></entry> 
<entry id="4" time="2017-11-15 19:23:07"><![CDATA[101|0|0|0|0]]></entry> 
<entry id="5" time="2017-11-15 19:23:07"><![CDATA[103|665|0|0|10]]></entry> 
<entry id="6" time="2017-11-15 19:23:16"><![CDATA[2|938|738|580]]></entry> 
<entry id="7" time="2017-11-15 19:23:16"><![CDATA[110|0|0|2000|0]]></entry> 
<entry id="8" time="2017-11-15 19:23:16"><![CDATA[109|0|1|1|0]]></entry> 
</gameover> 
</client> 

答えて

0

あなたが使用できるカスタムボディ(XML)でHTTPリクエストを送信する場合:あなたが使用できるxmlファイルをアップロードする場合

Response r = Jsoup.connect(host).requestBody(body).method(Method.POST).execute(); 

Response r = Jsoup.connect(host + path).data(key, filename, inputStream).method(Method.POST).execute(); 

あなたの応答がhtmlでない場合(例:xml).ignoreContentType(true)を使用する必要があります。

私はこれがあなたに役立つことを願っています

関連する問題