登錄界面,首先隨意輸入一個賬號,登錄查看發送表單的請求
可以發現請求是Post : https://www.zhihu.com/login/phone_num
發送的表單是
_xsrf:
password: 密碼 無需加密
captcha: 驗證碼 無需驗證碼時為不用此項 ,需要驗證碼時為驗證碼圖片倒立字體坐標
captcha_type:cn
phone_num: 賬號
1 package 知乎模擬登錄; 2 3 import org.apache.http.HttpEntity; 4 import org.apache.http.NameValuePair; 5 import org.apache.http.client.entity.UrlEncodedFormEntity; 6 import org.apache.http.client.methods.CloseableHttpResponse; 7 import org.apache.http.client.methods.HttpPost; 8 import org.apache.http.impl.client.CloseableHttpClient; 9 import org.apache.http.impl.client.HttpClients; 10 import org.apache.http.message.BasicNameValuePair; 11 import org.apache.http.protocol.HTTP; 12 import org.apache.http.util.EntityUtils; 13 14 import java.util.ArrayList; 15 import java.util.List; 16 17 public class GetProblem { 18 public static void main(String[] args) throws Exception { 19 CloseableHttpClient closeableHttpClient = HttpClients.createDefault() ; 20 HttpPost httpPost = new HttpPost("https://www.zhihu.com/login/phone_num") ; 21 List<NameValuePair> nvps = new ArrayList<NameValuePair>(); 22 nvps.add(new BasicNameValuePair("_xsrf", "66653239623962342d396237632d346233332d396331362d333434386438326438616139")); 23 nvps.add(new BasicNameValuePair("password", "33665511886622")); 24 nvps.add(new BasicNameValuePair("captcha_type", "cn")); 25 nvps.add(new BasicNameValuePair("phone_num", "15890956765")); 26 27 httpPost.setEntity(new UrlEncodedFormEntity(nvps)); 28 CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpPost) ; 29 HttpEntity entity = closeableHttpResponse.getEntity() ; 30 String s = EntityUtils.toString(entity); 31 System.out.println(s); 32 } 33 }
可能出現的情況
請求返回體為:
{
"r": 1,
"errcode": 1991829,
"data": {"captcha":"\u9a8c\u8bc1\u7801\u9519\u8bef"},
"msg": "\u9a8c\u8bc1\u7801\u9519\u8bef"
}
"errcode": 1991829