Line 23 should work, as HttpClient has a method execute(HttpUriRequest request) and HttpPost implements HttpUriRequest.
NameValuePair has two constructors. One takes no arguments, the other takes a String and an org.omg.COBRA.Any. You are providing two Strings. So you need to wrap that second String into an Any. Unfortunately, I see no sub classes for Any so you'll need to create one yourself.
Edit: indeed the wrong NameValuePair. But that would make me think the creation of entity would already cause an error. Odd...
Ulf Dittmer wrote:Declare the client object as DefaultHttpClient, not HttpClient (which has abstract methods only).
What about declaring against interfaces? I wouldn't declare it as DefaultHttpClient unless I needed to call methods not declared in HttpClient.
Alan Blass
Ranch Hand
Joined: Mar 21, 2010
Posts: 106
posted
0
Rob Prime wrote:Line 23 should work, as HttpClient has a method execute(HttpUriRequest request) and HttpPost implements HttpUriRequest.
errmm...it is still giving me "cannot find symbol". Am I right to say that I cast httpPost into HttpUriRequest to make it work?
NameValuePair has two constructors. One takes no arguments, the other takes a String and an org.omg.COBRA.Any. You are providing two Strings. So you need to wrap that second String into an Any. Unfortunately, I see no sub classes for Any so you'll need to create one yourself.
Edit: indeed the wrong NameValuePair. But that would make me think the creation of entity would already cause an error. Odd...
Rob Prime wrote:Line 23 should work, as HttpClient has a method execute(HttpUriRequest request) and HttpPost implements HttpUriRequest.
errmm...it is still giving me "cannot find symbol". Am I right to say that I cast httpPost into HttpUriRequest to make it work?
Update your libraries. I downloaded version 4.0.3, made changes to the declaration and instantiation of NameValuePair, and it compiled successfully. Well, apart from an uncaught exception.
NameValuePair has two constructors. One takes no arguments, the other takes a String and an org.omg.COBRA.Any. You are providing two Strings. So you need to wrap that second String into an Any. Unfortunately, I see no sub classes for Any so you'll need to create one yourself.
Edit: indeed the wrong NameValuePair. But that would make me think the creation of entity would already cause an error. Odd...
How do I wrap the second String into an Any?
I you've read my update you'd seen that you used the wrong NameValuePair, and I looked at this wrong one. You need to import org.apache.http.NameValuePair instead, and instantiate as org.apache.http.message.BasicNameValuePair:
After this the creation of entity still fails because an uncaught exception but the other lines compile just fine.
Alan Blass
Ranch Hand
Joined: Mar 21, 2010
Posts: 106
posted
0
Hi Rob,
I have checked and my libraries are httpclient-4.0.3.jar and httpmime-4.0.3.jar for this project.
The httpclient.execute(httpPost); is still giving me "cannot find symbol". Any ideas?
The formparams.add(new BasicNameValuePair("param2", "value2")); is also giving me "cannot find symbol".
But formparams.add(new NameValuePair("param1", "value1")); is not.
Did you add all dependencies of HttpClient as well? I'm missing httpcore there, which is definitely in the ZIP file with the dependencies.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35224
7
posted
0
Post the list of import statements. Make sure all classes you're using are covered by those imports, and that none of them is from the org.omg.CORBA.* hierarchy.
Alan Blass
Ranch Hand
Joined: Mar 21, 2010
Posts: 106
posted
0
Hi!
I downloaded the HttpClient and the dependencies:
Library Files: