0

I am trying to send a String[] array in j2me using ObjectOUputStream, but i keep getting this error,

java.lang.IllegalArgumentException: Not an HTTP URL

Here is my code:

    OutputStream os=null;
    HttpConnection hc= null;
    ObjectOutputStream oj=null;

    //get the URL
    String serverURL=entry.getUrl();

    hc=(HttpConnection)Connector.open(serverURL, Connector.READ_WRITE, true);
    hc=(HttpConnection)Connector.open(serverURL);


    hc.setRequestMethod (HttpConnection.POST);
    hc.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
    hc.setRequestProperty ("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
    hc.setRequestProperty ("Content-Language", "en-US");

    System.out.println ("Posting to the URL: " + entry.getVectorParams());

    //open the output stream to send the post parameters
    //os=hc.openOutputStream();

    oj=(ObjectOutputStream)hc.openOutputStream();
    //writing post parameters
    String[] bg=entry.getVectorParams();

    oj.writeObject(bg);

Please give a suggestion.

I checked my URL, it is correct and regarding Connector.open(), i pasted it twice here, not in my actual code. Is there anything else that I am doing wrong?

The System.out.println("Posting to the URL: " + entry.getVectorParams()), this only prints the post parameters, I have the serverurl passed in here:

String serverURL=entry.getUrl();
hc=(HttpConnection)Connector.open(serverURL, Connector.READ_WRITE, true);

My server URL is : http://localhost:8080/Web/gServer.jsp

1 Answer 1

1

The value of your serverURL variable must not be a valid URL. Try printing it out, and checking.

You have this debug statement:

System.out.println ("Posting to the URL: " + entry.getVectorParams());

but that is printing out the params, not the url. You should print out the serverURL variable.

Also, you are calling Connector.open() twice in a row. There's no need for that.

Update: I also think there could be a problem with the way you're writing the POST parameters to your connection's OutputStream. I wouldn't use an ObjectOutputStream. See something like this for an example of making J2ME POST calls. Basically, you make a String of the POST parameters, separated by &, and then use String.getBytes() to convert to a byte[] for writing to the OutputStream.

Sign up to request clarification or add additional context in comments.

9 Comments

Yes, i checked my URL, it is correct and regarding Connector.open(), i pasted it twice here, not in my actual code. Is there anything else that i am doing wrong. The system.out.println("Posting to the URL: " + entry.getVectorParams()), this only prints the post parameters, i have the serverurl passed in here String serverURL=entry.getUrl(); hc=(HttpConnection)Connector.open(serverURL, Connector.READ_WRITE, true); My server URL is : localhost:8080/Web/gServer.jsp
Can you post the exact URL for us to see?
when you use the URL in the code, are you adding "http://" on to the front of it? have you tried that? I can't tell, with Stack Overflow's comment formatting, if you included that, or not.
So, I noticed that the hostname in your URL is localhost. Is that really correct? Are you running this app on a desktop simulator? If you're pointing at http://localhost:8080, then you have an application server installed on your J2ME device? I'm wondering if the device detects the localhost hostname, and assumes that to be wrong, because some J2ME phones might not allow local services. Can you tell us which device, or simulator, you're running on? Have you tried another URL, that is not on localhost?
when i dont use ObjectOutputStream, it works fine and i can send my parameters to the URL, but when i use the ObjectOutputStream, this error pops up. I am accessing the server on my localhost, that is my server side code is there on my machine, and i connect the emulator to it by sending the mobile form parameters.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.