2011-10-26 44 views
3

我正在写一个小应用程序,它根据http POST中的一些变量从Web服务器检索一些html。返回的HTML数据有一个<pre>部分,其中有一些单词使用换行符和制表符分隔很好,但我的应用程序没有收到它们。代码如下所示Apache HTTPClient不处理换行符

HttpPost post = new HttpPost("REMOVED FOR PRIVACY"); 

    try { 
     // Add your data 
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
      //REMOVED FOR PRIVACY 

     post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

     // Execute HTTP Post Request 
     HttpResponse response = httpClient.execute(post, httpContext); 
     String htmlBrief = inputStreamToString(response.getEntity().getContent()).toString(); 
     return htmlBrief; 
     } 

我想可能是我如何把它通过一个BufferedReader像这样

private StringBuilder inputStreamToString(InputStream is) throws IOException { 
    int c; 
    StringBuilder total = new StringBuilder(); 

    // Wrap a BufferedReader around the InputStream 
    BufferedReader rd = new BufferedReader(new InputStreamReader(is)); 

    // Read response until the endIndex 
    while ((c = rd.read()) != -1) { 
     total.append((char)c); 
    } 

    // Return full string 
    return total; 
} 

读取响应我想这可能是因为我在在线阅读在缓冲式阅读器中,所以我一次转换到一个字符,但它没有帮助解决问题。

任何帮助将不胜感激。

谢谢,本

+0

你试过rd.readLine()吗?为什么你使用BufferedReader而没有从缓冲中获益呢? – pawelzieba

+0

是的,我试过读行。我转而只读,因为我认为readline是我失去我的新线人物的原因。 –

+0

换行输入流,看看究竟在流中。 – pawelzieba

回答

0

使用CharlesFiddler检查什么是在HTTP请求的身体实际发送。

最有可能的问题:

  • 不匹配的字符集客户端&服务器;
  • 未解码URL编码的正文。