cancel
Showing results for 
Search instead for 
Did you mean: 

http Header POST/GET + QueryStrings

Former Member
0 Kudos

Hi,

I am facing the following problem:

I need to create an URL with a QueryString something like:

http://

/index.asp?var1=a&var2=b


and then this needs to be sent via

POSTmethod

to the webserver! Otherwise when using GET, I get redirected to a login-page. I checked this with an html-page, which carries a corresponding form - this works with POST Method. I need to get the url or the source of the response page in webdynpro!

Or is there a way to simulate the html-form?

I think there are jars available, which can sent files to an url - I thought about sending an html-header, as the form-POSTMethod puts the form variables in the html-Header, when sending. Is this possible?

Right now I am using the following classes:

import org.apache.commons.httpclient.HttpClient;

import org.apache.commons.httpclient.HttpException;

import org.apache.commons.httpclient.methods.*;

I am sending the URL via this:

		PostMethod post = new PostMethod(<b>url.toExternalForm()</b>);

		post.setRequestHeader("Content-type", "text/html; charset=ISO-8859–1");

		HttpClient httpclient = new HttpClient();
		
		int iResultCode = httpclient.executeMethod(post);

		msgMgr.reportSuccess("iResultCode = " + iResultCode);

		byte[] yaResponse = post.getResponseBody();

		msgMgr.reportSuccess("Server response:"+new String(yaResponse));
		
		post.releaseConnection();

does somebody know, if "url.toExternalForm()" creates something like a form, which then again can be sent via POST? right now i get redirected to a login-page. So it seems my postMethod is infact a GET...

any ideas welcome,

thanx matthias

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Hello Matthias,

This 2 documents seems for me pretty detailed to solve your problem:

http://jakarta.apache.org/commons/httpclient/methods/post.html

http://java.sun.com/j2se/1.4.2/docs/api/java/net/URL.html#toExternalForm()

Best regards, Maksim Rashchynski.

Answers (0)