发布到http字段/表单的Java会一直失败

时间:2011-10-31 00:35:56

标签: java html http networking

好的,所以我尝试了很多东西,包括套接字,httpConnection,httpClients,代理,使用cookie,以及其他各种各样的东西,但这只是一直在失败。我需要我的程序做的是将一些数据发送到html网站然后回复适当的反应。但是resposne总是与我的预期完全相反。我所谈论的更具体的网站是http://hidemyass.com,我需要将字段值设置为“http:// reddit。 com“你的名字是你,然后按下按钮女巫将通过代理重定向到Reddit.So理论上我应该得到的是Reddit html源代码或常规服务器响应。但我一直得到的是http://hidemyass.com html源代码设置了默认值的代码(也就是说我没有通过与它的连接发送这些值)。

所以这就是我所做的,但它没有用。

CODE:

//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));
}

有人能帮助我最终看到我的错误并让网站做我想做的事吗?

1 个答案:

答案 0 :(得分:0)

您必须将您的请求发布到表单的操作网址:

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