目标主机不能为null或parameters.scheme = null,则主机= null时设置 [英] Target host must not be null or set in parameters.scheme=null,host=null

查看:306
本文介绍了目标主机不能为null或parameters.scheme = null,则主机= null时设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我getinng以下异常:

i am getinng the following exception:

    Target host must not be null or set in parameters.scheme=null,
host=null,path=/webservices/tempconvert.asmx/FahrenheitToCelsius

我的源$ C ​​$ C:

My source code:

public class ParActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView t=new TextView(this);
        String encodedUrl = null;
      //  setContentView(R.layout.main);

                HttpClient client = new DefaultHttpClient();  
               //String query = "?Fahrenheit=26";
            //  String host = "www.w3schools.com/webservices/tempconvert.asmx/";
            //   encodedUrl = host + URLEncoder.encode(query,"utf-8");
            //  int p=(Integer) null;
              // URI uri = URIUtils.createURI("vv", "www.w3schools.com", 50, "/webservices/tempconvert.asmx", "?Fahrenheit=26", null);

                try{ 
               String postURL = "/webservices/tempconvert.asmx/FahrenheitToCelsius";
                HttpPost post = new HttpPost(postURL);
              // post.addHeader("scheme","vv");
               // post.setHeader("host", "www.w3schools.com");
                String PostData="36";
                StringEntity httpPostEntity = new StringEntity(PostData, HTTP.UTF_8);
                post.setEntity(httpPostEntity);
                post.setHeader("host", "www.w3schools.com");
                post.setHeader("Content-Length", new Integer(PostData.length()).toString());
                post.setHeader("Content-Type", "application/x-www-form-urlencoded");


                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
               // nameValuePairs.add(new BasicNameValuePair("host", "www.w3schools.com"));
                nameValuePairs.add(new BasicNameValuePair("Fahrenheit", "26"));
               post.setEntity(new UrlEncodedFormEntity(nameValuePairs));


               HttpResponse responsePOST = null;
                // Execute HTTP Post Request
               // HttpResponse response = httpclient.execute(post);
                client.getConnectionManager();



                   responsePOST = client.execute(post); 
                HttpEntity resEntity = responsePOST.getEntity();  
                String response=EntityUtils.toString(resEntity);
                response=response.trim();
              //  Log.i("RESPONSE=",response);
                t.setText("response"+response);
                setContentView(t);
        } catch (Exception e) {
            // TODO Auto-generated catch block
           //e.printStackTrace();
            t.setText("ex"+e.getMessage());
        setContentView(t);
        }
    }

}

我要调用的Web服务在: <一href="http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit">http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit

i want to invoke the webservice at: http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit

使用HttpClient.How我应该给主机和方案的投入?

using HttpClient.How should i give host and scheme as input?

请帮忙...

推荐答案

这是您的主机错误 你逝去的www.w3schools.com post.setHeader(主机,www.w3schools.com); 行,而不是你必须通过http://www.w3schools.com

This is your Host error You are passing "www.w3schools.com" in post.setHeader("host", "www.w3schools.com"); line instead you have to pass "http://www.w3schools.com"

您可以从<一指同样的问题href="http://h3x.no/2010/11/22/httpclient-target-host-must-not-be-null-or-set-in-parameters">here

这篇关于目标主机不能为null或parameters.scheme = null,则主机= null时设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆