2011-05-03 45 views
0

我使用HttpPost在Android中发送MMS时出错。使用HTTP的错误发布

在它说的logcat:

ERROR /这里(447):---------错误-----目标主机不能为空,或者参数进行设置。

我的示例代码:

String url = "myurl"; 
HttpClient httpClient = new DefaultHttpClient(); 

try { 
    httpClient.getParams().setParameter(url, new Integer(90000)); // 90 second 
    HttpPost post = new HttpPost(url); 
    File SDCard = Environment.getExternalStorageDirectory(); 
    File file = new File(SDCard, "1.png"); 
    FileEntity entity; 
    entity = new FileEntity(file,"binary/octet-stream"); 
    entity.setChunked(true); 
    post.setEntity(entity); 
    post.addHeader("Header", "UniqueName"); 
    Log.i("MMSHTTP","----post---------------"+post); 

    HttpResponse response = httpClient.execute(post); 

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { 
     Log.e("Here", 
       "--------Error--------Response Status line code:" + response.getStatusLine()); 
    } 
    else 
    { 
     // Here every thing is fine. 
    } 

    HttpEntity resEntity = response.getEntity(); 
    if (resEntity == null) { 
     Log.e("Here","---------Error No Response!!-----"); 
    } 
} catch (Exception ex) { 
    Log.e("Here","---------Error-----"+ex.getMessage()); 
    ex.printStackTrace(); 
} finally { 
    httpClient.getConnectionManager().shutdown(); 
} 

如何解决这个错误吗?

+0

请添加更多信息,例如发生错误的一段代码。 – Michael 2011-05-03 05:12:12

+0

哪条线给你提到的错误? – rekaszeru 2011-05-03 05:34:57

回答

2

你指定的URL是在你的代码示例是:HttpClient的是能够确定的主机名

String url = "myurl"; 

为了让,你将需要提供有效的URL。沿线的东西:

String url = "http://myurl.com/index"; 

注意:'http://'是重要的,以便可以确定适当的协议。

This guy也有同样的问题。

+0

我得到了正确的uri链接..为了更好的理解我把它作为“myurl” – info 2011-05-05 10:49:50