Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Idhttp, how to send the data in idhttp.request

Status
Not open for further replies.

HelpMEDude

Programmer
Feb 27, 2005
21
SE
Hello, I guess no-one remembers me when i posted here for over one year ago, but now I'm back :).

I'm having trouble to simply send the values in idhttp.request to a webisite, the help file says: "Specifies the header values to send to the HTTP server.", however I have not found out how to send that darn data :(.

Ive tried using idhttp.get(url) but it doesn't include the values (host value for example) when it sends, it does however include the Custom header (I've checked the outgoing data with a program called ethereal).

What I'm trying to say is: Is there any proc/func to simply send all the values you entered in the idhttp.request.

Also you might want to know: I use Indy 10, Delphi 2005 and want to send POST-data.

I hope you can help me :D
 
Check out my post in thread102-627709. It shows how to pass parameters in the url.

Hope this helps!

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Correction. My second sentence should read:
"It shows how to pass parameters via an HTTP POST."

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Nope, it just crushed at the http.post-line, thank you anyway tough.

I began worrying we ain't talking about the same thing when you wrote the parameter examples:

ParamData.WriteString('username=' + Username);
ParamData.WriteString('&password=' + Password);
ParamData.WriteString('&x=43');
ParamData.WriteString('&y=8');

Cause the things I want to send should always be like:

ParamData.WriteString('POST HTTP/1.1');
ParamData.WriteString('Host: ParamData.WriteString('Content-length: 233');
ParamData.WriteString('');
ParamData.WriteString('=false&view'); (and then like 233 characters containing the POST-data)

Sorry if I wasn't clear enough in my first post :/.
 
Oh I see, I didn't interpret your question correctly.

See if these links are useful/give you any clues:

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Check the TIdHTTP.Request property. You can set the standard headers there and add your own ones.

Code:
Socket.Request.ContentType := 'application/x-[URL unfurl="true"]www-form-urlencoded';[/URL]
Socket.Request.UserAgent := "My agent name";

Note 1: this header is mostly mandatory for Indy post.

The post data is another thing:

Code:
Pars := TStringList.Create;
Pars.Add('txtTarget=abc');
Pars.Add('&txtArea=' + Area);
Pars.Add('&txtTitle=Robot');
Pars.Add('&txtPageNr=1');
Pars.Add('&txtItemsPage=10');
Res  := TStringStream.Create('');
Socket.Post(URL, Pars, Res);  // See Note

Note: the Request.ContentType shown above is mostly mandatory for Indy post.

buho (A).
 
Stretchwickster - The third link i found useful, thank you :).

buho - Yea, it seems so, I've mixed up two things (one i still dont understand what it is...), but my question from the start was how to send all those (in idhttp.request) things/values to a server, I've not found any procedure that does that :(

Finally I must say that what I wanted to do is now working with that component i downloaded (From the third link in Stretchwickster's post).

Thank you
happy.gif
 
Lets go for a HTTP 101 class :) :)

Considere this code:

Code:
    Socket.Request.ContentType := 'application/x-[URL unfurl="true"]www-form-urlencoded';[/URL]
    Socket.Request.ContentType := 'application/x-[URL unfurl="true"]www-form-urlencoded';[/URL]
    Socket.Request.UserAgent := "My agent name";
    Pars := TStringList.Create;
    Pars.Add('txtTarget=abc');
    Pars.Add('&txtArea=area');
    Pars.Add('&txtTitle=Robot');
    Pars.Add('&txtPageNr=1');
    Pars.Add('&txtItemsPage=10');
    Res  := TStringStream.Create('');
    Socket.Post(URL, Pars, Res);

Where Socket is a TIdHTTP.

If you execute the code pointing to an URL able to show you the HTTP headers you will see:

Accept: text/html, */*
Connection: keep-alive
Host: User-Agent: My agent name
Content-Length: 73
Content-Type: application/x-
and may be a couple other headers like cookies and so on.

You don't need to manually add the headers (other than the Content-Type and may be the User-Agent ones), the socket will add them as needed.

If your page can show the Request.Form server construct, you'll see:

txtTarget=abc
txtArea=area
txtTitle=Robot
txtPageNr=1
txtItemsPage=10

Basically, you need to feed the socket only with your POST fields; most of the time you don't need to bother with the request headers.

buho (A).
 
Do you have sample code that would work to a HTTPS site sending an XML file ?
 
Hello,

I'm not sure really what XML or HTTPS is :(.

If you mean I've got a code that can send HTTPS data (I assume HTTPS is alike HTTP protocol) and recive XML (I assume XML is alike HTML) data, then no, I send HTTP and recive HTML code using
(but maybe it can aswell send HTTPS-data, I'm not sure)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top