Hi i am trying do a server request using HttpURLConnection POST method , but not receiving any response, i saw few posts here in SO but i am unable understand them . Below is my code
@Override
protected String doInBackground(Void... arg0) {
try{
System.out.println("inside try clockr=====");
String urlParameters = "Username=sadmin&Password=s4dm1ncoe";
String request = "http://10.xx.xx.xxx/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&Username=sadmin&Password=s4dm1ncoe";
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
connection.connect();
System.out.println("checking response=====");
//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
System.out.println("checking response====="+response.toString());
return response.toString();
//connection.disconnect();
}catch(Exception e){
System.out.println("checking error====="+e.toString());
return new String("Exception: " + e.getMessage());
}
}
}
The above code gives me error FilenotfoundExcepttion stacktrace as below
07-15 12:35:47.656: I/System.out(30352): checking error=====java.io.FileNotFoundException: http://10.xx.xx.xxx/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&Username=sadmin&Password=s4dm1ncoe
This is my URL http://10.xx.xx.xxx/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&Username=sadmin&Password=s4dm1ncoe"
can someone help explain how to set parameters for my url?