Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java code to generate curl Get Http request

 
Comly Wilson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all!

I am new to the forum, and pretty new to Java in general, so apologies in advance for any stupid questions.

Anyway, I am trying to generate this request with my Java program, but I just can't seem to figure it out:


curl -v -H "Authorization:Basic MY_AUTH_CODE" -H "Accept:application/xml" -H "app_id:MY_APP_ID" -H "app_key:MY_APP_KEY" -X GET "THIRD_PARTY_URL"


I tried to generate a query string, but I keep getting 403 errors. I also tried to input my parameters using URLConnection.getRequestProperty("name", "value"), but that didn't work either.

Any help would be greatly appreciated.

Thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should get familiar with the JavaDocs for URLConnection and HttpURLConnection.

Have you succeeded in getting the connect() method to run?

Bill

 
Comly Wilson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I tried using URLConnection and the setRequestProperty to my authorization, app_id and app_key, but I am getting a 403 error (Forbidden, the credentials are not authorized).

I am pretty confident it is a problem with my setup, not with my actual authorization.

Here is a stripped down version of the code for your reference:
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JavaDocs for URLConnection:


The connection object is created by invoking the openConnection method on a URL.
The setup parameters and general request properties are manipulated.
The actual connection to the remote object is made, using the connect method.
The remote object becomes available. The header fields and the contents of the remote object can be accessed.

The setup parameters are modified using the following methods:

setAllowUserInteraction


Where is your connect() call?

More from javadocs
The following methods are used to access the header fields and the contents after the connection is made to the remote object:

getContent
getHeaderField
getInputStream
getOutputStream


You can't getInputStream until you have connect() ed

I'm assuming your real code is going to handle the IOException to get the stack trace.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!