0

Can someone help me better understand this code better.

// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

Mainly i just need help figuring out the URL part.

url += "?" + paramString;

how can i better customize that part of the code?

On customization i want to take my current url

academic_programs_xml/oncampus-departments.xml

and change it to

academic_programs_xml/oncampus-associates.xml

my thoughts are that you can take the url for the location

academic_programs_xml/

then add the param to the url then add .xml

something like this maybe?

url += paramString + ".xml";

Josh C.
  • 316
  • 1
  • 4
  • 14

2 Answers2

1

here we are adding parameters to a URL Lets take an example.

Base URL : www.example.com/index.php

If we want to add the parameter { search = hello }

we would do so like this

Param URL : www.example.com/index.php?search=hello

Basically, anything after the ? mark in the end of the URL, are key value pair parameters.

Now back to your code, You create a key-value pair string of parameters in the code

String paramString = URLEncodedUtils.format(params, "utf-8");

Then you are appending it to the URL after adding a question mark with the code

url += "?" + paramString;

I hope that's clear.

Ahmed Aeon Axan
  • 2,139
  • 1
  • 17
  • 30
0

On figuring out: The "?" marks the end of the URI path section and the start of the query string. The Query string is usually used to encode parameters e.g. during a call to an web service.

On customizing, it is not clear what you mean.

stevejpurves
  • 923
  • 1
  • 7
  • 12