1

我想发布到这个网址

http://abc.com/Registration.aspx?MailID=PickUp&UserName=as&PickUpTime=19191919&Notes=bla&DeviceId=0000

HttpPost httppost = new HttpPost("http://abc.com/Davis/Registration.aspx");
    httppost.setHeader("MailID","MailID=PickUp");
    try {
        // Add your data

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        //nameValuePairs.add(new BasicNameValuePair("MailID","PickUp"));
        nameValuePairs.add(new BasicNameValuePair("UserName","as"));
        nameValuePairs.add(new BasicNameValuePair("PickUpTime",date));
        nameValuePairs.add(new BasicNameValuePair("Notes",note));
        nameValuePairs.add(new BasicNameValuePair("DeviceId",deviceID));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

另外我怎么知道我正在传递什么网址。我怎样才能记录它?

4

1 回答 1

1

您确定 MailID 应该在标题中吗?从问题的措辞来看,似乎所有值都在查询字符串中(在 ? 标记之后的 URL 中)。但是那你为什么需要 POST 呢?一个 GET 就足够了。

在标头中传递数据(例如 MailID)几乎是闻所未闻的。Querystring 和 POST 表单,这些是最受欢迎的地方。

所以先搞清楚服务端页面的接口。它是否期望 GET 或 POST(或两者之一)?然后将字段放置到正确的位置 - 放置到 URL(通过字符串连接)或实体中。

哦,您传递的 URL 是http://abc.com/Davis/Registration.aspx. 既不setHeader()也不setEntity()修改 URL 本身。

于 2012-08-19T00:10:19.693 回答