gpt4 book ai didi

android - 如何替换 URL 中的一个单词

转载 作者:行者123 更新时间:2023-11-29 14:47:39 25 4
gpt4 key购买 nike

<分区>

在我的网址中,我想用“house”替换“{chamber}”

public class MainActivity extends Activity {

private static String url ="http://10.11.32.199/congressionaldirectory/services/getbillsdetailsbychamber?chamber={chamber}&app_code=125143649";

String jsonStr;
TextView tv;

private static final String TAG_CHAMBER = "chamber";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv=(TextView) findViewById(R.id.textView1);

new GetContacts().execute(url);
}

private class GetContacts extends AsyncTask<String,String,String> {

@Override
protected void onPreExecute() {
super.onPreExecute();


}

@Override
protected String doInBackground(String... params) {

HttpClient httpclient=new DefaultHttpClient();
URI u;
try {
u = new URI(params[0]);
HttpPost HG=new HttpPost(u);

ArrayList<NameValuePair> al=new ArrayList<NameValuePair();
al.add(new BasicNameValuePair(TAG_CHAMBER,"house"));
HG.setEntity(new UrlEncodedFormEntity(al));
HttpResponse response=httpclient.execute(HG);


jsonStr = EntityUtils.toString(response.getEntity());

Log.d("Response: ", "> " + jsonStr);

} catch (URISyntaxException e) {

e.printStackTrace();
}
catch (ClientProtocolException e) {

} catch (IOException e) {

e.printStackTrace();
}

return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
tv.setText(jsonStr);}}}

如果我直接传递这个 url ( http://10.11.32.199/congressionaldirectory/services/getbillsdetailsbychamber?chamber=house&app_code=125143649 ) 它工作正常请帮助我

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com