用于Facebook的HTTP Post请求无法正常工作?

时间:2017-05-05 15:02:29

标签: java web http-post

字符串httpsURL =" https://m.facebook.com/login/identify/?ctx=recover&c=https%3A%2F%2Fm.facebook.com%2Flogin%2F&lwv=100&_rdr&#34 ;;

    String query = "email="+URLEncoder.encode("myemailaddress@gmail.com","UTF-8"); 

    URL myurl = new URL(httpsURL);
    HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
    con.setRequestMethod("POST");
    con.setRequestProperty("Content-length", String.valueOf(query.length())); 
    con.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
    con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0;Windows98;DigExt)"); 
    con.setDoOutput(true); 
    con.setDoInput(true); 

    DataOutputStream output = new DataOutputStream(con.getOutputStream());  


    output.writeBytes(query);

    output.close();

    DataInputStream input = new DataInputStream( con.getInputStream() ); 



    for( int c = input.read(); c != -1; c = input.read() ) 
        System.out.print( (char)c ); 
    input.close(); 

    System.out.println("Resp Code:"+con .getResponseCode()); 
    System.out.println("Resp Message:"+ con .getResponseMessage());
    ![enter image description here](https://i.stack.imgur.com/gVUc3.png)![enter image description here](https://i.stack.imgur.com/3RihL.png)

0 个答案:

没有答案