Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-通过文本文件传递Url_Java_Android_Http_Url_Request - Fatal编程技术网

Java Android-通过文本文件传递Url

Java Android-通过文本文件传递Url,java,android,http,url,request,Java,Android,Http,Url,Request,我试图通过字段文本传递url以生成HttpPost,但出现以下错误: Target host must not be null, or set in parameters. scheme=null, host=null, path=android.support.v7.widget.AppCompatEditText%7B1647e90+VFED..CL.+......I.+0%2C0-0%2C0+%237f0d00ad+app%3Aid%2Ffield_url%7D 这是我的密码 -服务 c

我试图通过字段文本传递url以生成HttpPost,但出现以下错误:

Target host must not be null, or set in parameters. scheme=null, host=null, path=android.support.v7.widget.AppCompatEditText%7B1647e90+VFED..CL.+......I.+0%2C0-0%2C0+%237f0d00ad+app%3Aid%2Ffield_url%7D
这是我的密码

-服务

class ThreadInBackgroud extends Thread{
    public void run(){
        try{

            Log.i("LOG", "LocationService.doInBackground()");
            HttpConnection.getSetDataWeb(URLEncoder.encode(Settings_Fragment.url,"UTF-8"),
                    "send-map-coords",
                    mMessageEB);
            stopSelf();

        }catch (Exception e) {
            Log.e("LOG", e.getMessage(),e);
        }

    }
}
-碎片

Button saveButton = (Button) view.findViewById(R.id.btn_save);
    saveButton.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {

            SharedPreferences.Editor editorUrl = getActivity().getSharedPreferences("url_key", MODE_PRIVATE).edit();
            editorUrl.putString("url_key", url_field.getText().toString());
            editorUrl.commit();

        }
    });

    url = url_field.toString();
-HttpConnection

 public static String getSetDataWeb(String url, String method, MessageEB m) throws UnsupportedEncodingException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(URLEncoder.encode(url,"UTF-8"));
我希望将url作为变量传递,以便用户可以通过文本字段更改url

url = url_field.toString();
url = url_field.toString();

因为需要调用
getText()
方法才能从输入字段中获取文本,否则调用视图对象上的
toString()
方法将给出它的
字符串表示形式

并公开url,以便您可以在其他服务中访问

public String url;

您不应该对整个URL进行编码,因为这将导致一些类似垃圾的错误

(http%3A%2F%2F23.23.82.251%3A9116%2Fsolr%2Fdb%2Fselect%3Fq%3D*%3A*%2B_val_%3A%2522geodist%2528%2529%2522%26fq%3D(ProviderType%3A10)%26rows%3D100%26wt%3Djson%26indent%3Dtrue%26fl%3DProviderID%2CProviderType%2CProviderName%2CProviderAddress%2CCityAreaID%2CCityAreaName%2CCity%2CState%2CLatlong%2Cscore%26fq%3D{!geofilt}%26sfield%3DLatlong%26pt%3D20.296059%2C85.82454%26d%3D5%26sort%3Dgeodist()%2520asc)
这将失败,因为无法将其解析为正常的HTTP URL

相反,尝试使用


HttpPost HttpPost=新的HttpPost(“URL/…”)

我不知道使用共享偏好是否是最好的方法嘿。通过这种修改,我能够获得存储在文本字段中的字符串。但我仍然在路径上遇到同样的错误。java.lang.IllegalStateException:目标主机不能为null,也不能在参数中设置。scheme=null,host=null,path=@ClaudioCastro:只需使用
HttpPost-HttpPost=newhttppost(url)嘿。通过这种修改,我能够获得存储在文本字段中的字符串。但我仍然在路径上遇到同样的错误。java.lang.IllegalStateException:目标主机不能为null,也不能在参数中设置。scheme=null,host=null,path=myurl.com/package/pack/pack.php
public String url;
(http%3A%2F%2F23.23.82.251%3A9116%2Fsolr%2Fdb%2Fselect%3Fq%3D*%3A*%2B_val_%3A%2522geodist%2528%2529%2522%26fq%3D(ProviderType%3A10)%26rows%3D100%26wt%3Djson%26indent%3Dtrue%26fl%3DProviderID%2CProviderType%2CProviderName%2CProviderAddress%2CCityAreaID%2CCityAreaName%2CCity%2CState%2CLatlong%2Cscore%26fq%3D{!geofilt}%26sfield%3DLatlong%26pt%3D20.296059%2C85.82454%26d%3D5%26sort%3Dgeodist()%2520asc)