views:

162

answers:

2

Hi,

I am using Net Beans for developing an application on S60. I made one page for user authentication and using .net wcf service to authenticate user. i am able to send data on .net service by HttpGet method but not able to get response back on java page.

I have tested it on fiddler with this url its working fine and returning response code 200, but not getting response code by java code. Following code i am using. Is some thing wrong here ?

httpConn = (HttpConnection)Connector.open(url); httpConn.setRequestMethod(HttpConnection.GET); httpConn.setRequestProperty("User-Agent", "Profile/MIDP-2.1 Confirguration/CLDC-1.1");

int respCode = httpConn.getResponseCode();

Thanks Rishabh

A: 

try user agent "Profile/MIDP-2.1 Configuration/CLDC-1.1"

Vivart
I have already tried by this but not working yet.
Rishabh
this is just a get http request.i will suggest that use this url on your mobile web browser and see the result. sometimes in organizations, admin blocks the requests from other user agents.
Vivart
Please give me the url where i can achive the response from iis server.
Rishabh
user the URL, that you are using in you code.
Vivart
A: 

Probably because of timeout too short? Try this...

URL url = new URL("http://www.google.com");
URLConnection conn = url.openConnection();
conn.setConnectTimeout(20 * 1000);  // 20 seconds connect timeout
conn.setReadTimeout(60 * 1000 * 1); // 1 minute read timeout

// read response
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String resp;

while ((resp = in.readLine()) != null) { // log response
    System.out.println(resp);
}

in.close();
Rosdi
Hi Rosdi, i am using j2me so its not supporting URLConnection class. Is there any way to increase time of connection with HttpConnection class which is i am using.
Rishabh
`HttpURLConnection` is a subclass of `URLConnection`. Should be able to use `setConnectTimeout(..)` and `setReadTimeout(..)`. But I never programmed on j2me so I am just guessing.
Rosdi
@Rishabh, I just checked, you cannot set timeout in j2me. So your problem is not because of timeout. I suggest you change your url to google.com or something like that to see whether the code can actually browse out.
Rosdi
Hi Rosdi, I am still getting that issue.
Rishabh
So the code is not the issue, must be the connection/proxy settings or something.
Rosdi
May be, so what should be the setting for connection/proxy ?when i debug "httpConn = (HttpConnection)Connector.open(url);" line.it asks me for allow connection for this session on s60 simulator, after allowing, it come on "int respCode = httpConn.getResponseCode();" line and asks for connection with iis server by 1 access point "winsock", after connect control goes on wcf service but never come back on client side/java page. This is the whole scenario.
Rishabh