Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.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 使用python cgi脚本拦截https(非http)中的json_Java_Python_Cgi - Fatal编程技术网

Java 使用python cgi脚本拦截https(非http)中的json

Java 使用python cgi脚本拦截https(非http)中的json,java,python,cgi,Java,Python,Cgi,我将https post请求中的json字符串发送到ApacheServert(请求将json数据发送到实际上是python脚本的CGIBIN脚本)。我使用标准的cgi呼叫- f=open("./testfile", "w+") f.write("usageData json = \n") <b>form = cgi.FieldStorage() formList =

我将https post请求中的json字符串发送到ApacheServert(请求将json数据发送到实际上是python脚本的CGIBIN脚本)。我使用标准的cgi呼叫-

 f=open("./testfile",  "w+")                                             
 f.write("usageData  json  =  \n")   
 <b>form = cgi.FieldStorage()  
 formList = ['Data']      
 str = form['Data'].value
 str = json.dumps(backupstr)
 </b>      
 print  backupstr

我怀疑发送端缺少一个或多个connection.setRequestProperty()设置,这就是为什么它启动脚本但没有读取url中的json字符串…我做错了什么

第二段代码不是Java吗?(如果是这样,最好在问题中添加该标记)json字符串有多长?服务器和客户端上的
GET
变量值的长度都有限制。是的,它不是GET请求,而是url中带有json字符串的POST请求。这在HTTP上有效吗?在我看来,您直接从客户机传递json,但试图将其作为服务器上的表单数据进行访问。
  HttpsURLConnection  connection  =   null;
  try{
     connection  = (HttpsURLConnection)url.openConnection();
     connection.setRequestMethod("POST");
     connection.setRequestProperty("Content-Type", 
                 "application/json");
     connection.setRequestProperty("Content-Length", "" + 
                  Integer.toString(jsonstring.getBytes().length));
     connection.setRequestProperty("Content-Language", "en-US");  
     connection.setUseCaches (false);
     connection.setDoInput(true);
     connection.setDoOutput(true);

     //Send request
     DataOutputStream wr = new DataOutputStream (
                     connection.getOutputStream ());
     //wr.writeBytes(jsonstring);
     wr.writeUTF(URLEncoder.encode(jsonstring,  "UTF-8"));
     wr.flush ();
     wr.close ();

     //Get Response 
     InputStream is = connection.getInputStream();
     BufferedReader rd = new BufferedReader(new InputStreamReader(is));
     String line;
     StringBuffer response = new StringBuffer(); 
     while((line = rd.readLine()) != null) {
         response.append(line);
     }
     rd.close();
     //response = httpClient.execute(request); 
  }
  catch (Exception e) 
  {
      System.out.println("Exception  "  +  e.getMessage());
      throw  e;
   }