2013-02-14 38 views
1

我需要我的字符串張貼到其HTML內容服務器,如何發佈數據具有查詢字符串的HTML內容

這裏是我的代碼

網址構建器

​​

而生成的URL貌似

domainname/pagename?myaction=dopost&mesg=Hello%2C%3Cbr%20%2F%3E%3Cbr%20%2F%3ETesting 

執行HTTP代碼

HttpGet getRequest = new HttpGet(url); 
getRequest.setHeader(CONTENT_TYPE, MIME_TEXT_HTML); // html/text, utf-8 
DefaultHttpClient client = new DefaultHttpClient(); 
HttpResponse response = client.execute(getRequest); 

但這不會公佈提前執行

感謝

+0

您是*發佈*與*獲取*請求?! – sschrass 2013-02-14 11:32:48

+0

是的我正在使用獲得請求發佈消息 – Pratik 2013-02-14 11:38:10

回答

0

也許一個愚蠢的錯誤後得到禁止錯誤,但後通常有HttpPost,而不是一個HttpGet 完成,如下所示:

// Create a new HttpClient and Post Header 
HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php"); 

try { 
    // Add your data 
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
    nameValuePairs.add(new BasicNameValuePair("id", "12345")); 
    nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); 
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

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

老兄我正在使用GET方法,對於我來說不是愚蠢的錯誤 – Pratik 2013-02-14 11:39:43

+0

爲研究或任何其他原因? – sschrass 2013-02-14 11:43:30

+0

我正在使用網絡API,所以我必須去這個 – Pratik 2013-02-14 11:47:08

相關問題