Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3633
  • Last Modified:

POST DATA with IdHTTP

Hi, could somebody help me with sending post data to a serveer and geting the answer?
I have this:

AnsiString rtf;
TStringStream * Send = new TStringStream(rtf) ;
IdHTTP1->Request->Accept="*/*";
IdHTTP1->Request->Referer="http://..................pl";
IdHTTP1->Request->ContentType="application/x-www-form-urlencoded";
Send->WriteString("postdatatobesent.......");
IdHTTP1->Post("http://...........................pl",Send);

I know it is sent, but how can I get the answer from the server?

Thanks
0
AL3X2
Asked:
AL3X2
  • 3
1 Solution
 
AL3X2Author Commented:
Ok, I found something...

AnsiString rtf;
TStringStream * Send = new TStringStream(rtf) ;
Send->WriteString("postdata.............");
TStringStream * Receive = new TStringStream();
IdHTTP1->Post("http://..................pl",Send, Receive);
MessageBox(NULL, Receive->ReadString(10).c_str(), "Title", MB_OK);

But The MsgBox is empty. Why? What am I doing wrong?
The ReadString is supposed to read the content, right?
0
 
AL3X2Author Commented:
I made it...

AnsiString rtf;
TStringStream * Send = new TStringStream(rtf) ;
TStringStream * Receive = new TStringStream();
Send->WriteString("user=XXXX"
                  "&pass=XXXXXX"
                  "&rcpt=%2B" +
                  GUI->CBX->Text +
                  GUI->TXT->Text +
                  "&text=" +
                  GUI->TXTText->Text +
                  (90 - GUI->TXTText->GetTextLen())
                  );
IdHTTP1->Post("http://xxxxxxxxxxxxxxxx.pl",Send, Receive);
MessageBox(NULL, Receive->DataString.c_str(), "Title", MB_OK);

But now, I can POST only once. Next time I click on the POST button, it will tell me "Connection closed gracefully". I know that this is good, it means that all the data was red and the socket was closed. but... How can I get rid of this?
0
 
AL3X2Author Commented:
Bah... I found it myself

IdHTTP1->DestroyComponents();  


Thanks for reading =)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now