Java发送到http字段/表单不断失败



好的,所以我已经尝试了很多东西,包括套接字,httpConnection, httpclient,代理,使用cookie,和其他东西的广泛数组,但这只是不断失败。我需要我的程序做的是发送一些数据到html网站,然后收到足够的响应。但是反应总是和我期望的完全相反。更具体一点的网站,我正在谈论的是http://hidemyass.com,我需要设置字段值为"http://reddit.com"谁的名字是u,然后按按钮,女巫将重定向到Reddit通过代理。理论上,我应该得到的响应是Reddit html源或常规服务器响应。但是我一直得到的是http://hidemyass.com html源代码的默认值设置(又名,因为我没有发送这些值通过连接到它)。

所以这就是我所做的,它没有工作。

代码:

//I will skip used import because I think they are not of importance
//Also try catch blocks will be skipped and not written
private static UrlEncodedFormEntity entity;
public static void main(String[] args){
    HttpClient client=new DefaultHttpClient();
    ArrayList<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("u","http://reddit.com");
    params.add(new BasicNameValuePair("hmabutton,"Hide My Ass");
    entity=new UrlEncodedFormEntity(params,null)//there is no encoding on this site
    HttpPost post=new HttpPost("http://hidemyass.com");
    post.setEntity(entity);
    HttpResponse response=client.execute(post);
    HttpEntity ent=response.getEntity();
    System.out.println(EntityUtils.toString(ent));
}

谁能帮助我看到我的错误,最后得到网站做我想要的?

你必须将你的请求发送到表单的action URL:

HttpPost post=new HttpPost("http://hidemyass.com/process.php");

最新更新