发送请求时出现此错误(java.net.ProtocolException:读取输入后无法写入输出。)

时间:2019-04-16 14:53:28

标签: java httprequest

我正在编辑个人资料instagram api,当我请求放置字符串时,这给了我输入和输出的错误

java.net.ProtocolException:读取输入后无法写入输出。

我没有尝试太多

private boolean replaceUserVb(String myVictim) throws Exception {
    System.out.println("inside replaceUserVb");
    boolean result = false;
    String string_11 ="5ad7d6f013666cc93c88fc8af940348bd067b68f0dce3c85122a923f4f74b251";
    String str = "signed_body=";
    StringBuilder text = new StringBuilder("signed_body=");
    text.append("{\"\"gender\"\":\"\"1\"");
    text.append("\"_csrftoken\"\":\"\"missing\"");
    text.append("\"_uuid\"\":\"\"");
    String guiid = randomAlphaNumeric(16);
    System.out.println("guiid >>"+ guiid);
    text.append(guiid);
    text.append("\"\",\"\"_uid\"\":\"\"3\"");
    text.append("\"external_url\"\":\"\"\"\",\"\"username\"\":\"\"");
    text.append(myVictim);
    text.append("\"");
    text.append("\"email\"\":\"\"");
    text.append("");
    text.append("\"");
    text.append("\"phone_number\"\":\"\"\"");
    text.append("\"biography\"\":\"\"\"");
    text.append("\"first_name\"\":\"\"\"\"}");
    System.out.println("text >>" + text.toString());
    String mainText = text.toString();
    //encrypt mainText with key string_11)
    String str2 = sMethod_4(string_11, mainText);
    String str3 = "&ig_sig_key_version=5";

    URL sendUrl = new URL("https://i.instagram.com/api/v1/accounts/edit_profile/");  
    HttpURLConnection httpConnection = (HttpURLConnection) sendUrl.openConnection();
        httpConnection.setDoOutput(true);
        httpConnection.setDoInput(true);
    httpConnection.setRequestMethod("POST");
    httpConnection.setAllowUserInteraction(true);
  String cookiesHeader = httpConnection.getHeaderField("Set-Cookie");
 List<HttpCookie> cookies = HttpCookie.parse(cookiesHeader);
 //httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// httpConnection.setRequestProperty("User-Agent", "Instagram 10.3.2 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)");
   // httpConnection.setRequestProperty("User-Agent", "Instagram 7.3.1 Android (21/5.0.1; 480dpi; 1080x1920; samsung/Verizon; SCH-I545; jfltevzw; qcom; en_US)");
    httpConnection.setInstanceFollowRedirects(true);
    httpConnection.setConnectTimeout(7500);
    httpConnection.setReadTimeout(7500);
//   httpConnection.setRequestProperty("X-IG-Connection-Type", "WIFI");
 //  httpConnection.setRequestProperty("X-IG-Capabilities", "3ToAAA==");

     try (OutputStreamWriter dataStreamToServer = new OutputStreamWriter(httpConnection.getOutputStream())) {
        dataStreamToServer.write(str + str2 + str3);
        dataStreamToServer.flush();
        dataStreamToServer.close();
    }
   BufferedReader dataStreamFromUrl;
  dataStreamFromUrl = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
  String dataFromUrl = "", dataBuffer = "";  
 // Writing information from the stream to the buffer
    while ((dataBuffer = dataStreamFromUrl.readLine()) != null) {
        dataFromUrl += dataBuffer;

    }

    /**
     * Now dataFromUrl variable contains the Response received from the *
     * server so we can parse the response and process it accordingly.
     */
   dataStreamFromUrl.close();

  System.out.println("Response: " + dataFromUrl);

    System.out.println("After geting and closing httpconnection");

    result = true;
    return result;
}

我希望输出成功编辑配置文件,但每次都会给我相同的错误

0 个答案:

没有答案