[英]How to decompress json data request at server side?
我有一個Python客戶端代碼,該代碼使用壓縮的 JSON數據命中URL 。
我想在java中 解壓縮並打印JSON數據(從客戶端請求中獲取)。
客戶代碼:
#!/usr/bin/python
import sys, getopt
import requests
import json
from zlib import compress
s = requests.session()
url = "http://1.1.1.1:8080/eventfull/send/data/"
payload = dict(
username="test",
password="test123",
emailid=sys.argv[1],
campaignfrom="info@newsletter.x.com",
send_id="1234",
istest="1",
render_id=sys.argv[2],
subject="Eventfull :: Services HeartBeat",
htmlbody="<html><body><p>Hi Team,</p></br></br><p>This is a Test Campaign to ensure eventfull calls are working as expected</p></br></br><p>Thanks,</p><br><p>Tech Team</p></body></html>",
textbody="Testing"
)
json_string = json.dumps(payload)
compressed = compress(json_string,9)
response = s.post(url, data=compressed )
print response.status_code
print response.content
謝謝大家的幫助,我可以通過它完成我的任務。 完成可能需要很長時間,但值得。 下面是我的工作代碼。 [值得分享]
@POST
@Path("/Data")
@Consumes("application/zip")
public Response uploadFile2(InputStream incomingData) {
try {
//Decompressing...
InflaterInputStream inf = new InflaterInputStream(incomingData);
//Extracting Json Data....
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject)jsonParser.parse(
new InputStreamReader(inf, "UTF-8"));
String name = (String) jsonObject.get("username");
}
catch(SQLException se){
System.out.println(se.getLocalizedMessage());
}
catch (Exception e) {
e.printStackTrace();
}
// return HTTP response 200 in case of success
return Response.status(200).entity("Success").build();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.