Mega Search
23.2 Million


Sign Up

Make a donation  
Http->Post [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket

Hello!

I'm trying to post an XML file over Http. I would like to send an xml file to an .aspx link. I'm using Embarcadero 2010 ( C++).
In this line

Http->Post("https://...aspx", pInputXML, pOutputXML);

i get the error: http/1.1 404 Not Found

Why i get the error? The Link exists...
I have no idea. What can i do?

I'm glad, if i get help.

Greetings

Edited by: Katharina Dorn on Jun 24, 2014 3:08 AM

Edited by: Katharina Dorn on Jun 24, 2014 3:50 AM

Edited by: Katharina Dorn on Jun 24, 2014 5:27 AM

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 24-Jun-2014, at 8:29 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit] [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hey thank you for your answer!

It expect the raw XML. 
I create an XML file with the information and i send the xml to the given link. Its for Online Sales. The purchase informations are in the xml file and i must send it to the .aspx link.

What can be the ways i can go? Only the link and the xml file are given. I don't have more informations.


i created this code:

std::auto_ptr httpPtr( new TIdHTTP(NULL) );
TIdHTTP *Http = httpPtr.get();
try
{	
TIdSSLIOHandlerSocketOpenSSL *SSL = new TIdSSLIOHandlerSocketOpenSSL(Http );
	Http->IOHandler = SSL;
	Http->HandleRedirects = true;
	Http->AllowCookies = false;
	Http->ConnectTimeout = 10000;
	Http->ReadTimeout = 10000;
	Http->Request->BasicAuthentication = true;
}
catch( const Exception &e )
{}

TMemoryStream *pInputXML = new TMemoryStream;

pInputXML->LoadFromFile("C:\\CBUILDER2010.src\\Project\\order.xml");

try
{
	TMemoryStream *pOutputXML = new TMemoryStream;
		try
		{
			Http->Request->ContentType = "text/xml";
			Http->Request->Method = 'POST';
			Http->Post("https://....aspx", pInputXML, pOutputXML);
		}
	__finally
	{
		delete pOutputXML;
	}
}
__finally
{
	delete pInputXML;
}

When i try this link i get : „http/1.1 404 not found“
When i try an other link i get: „socket error #0“

My Indy version is 10.5.5. Shall i upgrade my version? If yes, how can i do that?
I hope, that is the right version.


Thank you for your help,

greetings


> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Katharina wrote:
> 
> > I'm trying to post an XML file over Http. I would like to send an xml
> > file to an .aspx link.
> 
> That is entirely dependant on what format the ASPX is expecting.  Does it 
> expect the raw XML data as the enire POST body?  Or does it expect the file 
> to be uploaded using an HTML webform?  It makes a big difference in how you 
> use TIdHTTP in both scenarios.
> 
> > In this line
> > 
> > Http->Post("https://...aspx", pInputXML, pOutputXML);
> > 
> > i get the error: http/1.1 404 Not Found
> 
> That means the requested URL does not exist.  That could happen if either:
> 
> 1. you are posting to a non-existant URL, which has nothing to do with the 
> data you are posting.
> 
> 2. you are being redirected, possibly because you are posting wrong data, 
> and the URL being redirected to does not exist.
> 
> > Why i get the error?
> 
> Hard to say for sure without seeing the actual HTTP messages going back and 
> forth.
> 
> --
> Remy Lebeau (TeamB)

Edited by: Katharina Dorn on Jun 24, 2014 11:56 PM

Edited by: Katharina Dorn on Jun 25, 2014 12:03 AM

Edited by: Katharina Dorn on Jun 25, 2014 12:14 AM

Edited by: Katharina Dorn on Jun 25, 2014 2:25 AM

Edited by: Katharina Dorn on Jun 25, 2014 5:37 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 25-Jun-2014, at 8:37 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit] [Edit] [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi!

> > It expect the raw XML.
> 
> And you are SURE about that?


I need to do that. the company for the I establish the connection told me, that i need to send the Raw XML as part of the post.

> > pInputXML->LoadFromFile("C:\\CBUILDER2010.src\\Project\\order.xml");
> 
> You are not resetting the pInputXML->Position property back to 0 before calling 
> Post().


i wrote this part of code after the load from file method:

pInputXML->Position = 0;

I hope it is correct.


> > Http->Request->ContentType = "text/xml";
> 
> Are you SURE that the value ContentType that the server is expecting?  And 
> not "application/xml"?  If you use "text/", you should specify the XML's 
> charset as well:
> 
> {code}
> Http->Request->ContentType = "text/xml";
> Http->Request->CharSet = "utf-8";
> {code}


Thank you for the tip regarding the software fiddler.
I opened my page, to which i need to send my xml and i get the information:

- Accept: text/html, application/xhtml+xml, */*
- Accept-Language: de-DE,de;q=0.5
- Result 200

So i interpret that its possible to arrange a connection to this "https:// ... .aspx" page.



>  Is the  TIdHTTP::OnRedirect event being triggered?  Or does the TIdHTTP::Response::Location 
> property have a non-blank URL when the error occurs?

I wrote this code ( before i use the post method, because the program stop when i access the post method):


Http->OnRedirect; // result ---> {NULL, NULL}
Http->Response->Location; // result ---> {NULL}

If i debug this step by step i get the informations, that OnRedirect and Location are {NULL};

with which informations can i set the properties?


I don't know whats wrong. 


Thank you for your help!


greetings

____________________________________
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Katharina wrote:
> 
> > It expect the raw XML.
> 
> And you are SURE about that?
> 
> > pInputXML->LoadFromFile("C:\\CBUILDER2010.src\\Project\\order.xml");
> 
> You are not resetting the pInputXML->Position property back to 0 before calling 
> Post().
> 
> > Http->Request->ContentType = "text/xml";
> 
> Are you SURE that the value ContentType that the server is expecting?  And 
> not "application/xml"?  If you use "text/", you should specify the XML's 
> charset as well:
> 
> {code}
> Http->Request->ContentType = "text/xml";
> Http->Request->CharSet = "utf-8";
> {code}
> 
> > Http->Request->Method = 'POST';
> 
> You do not need to set that manually, Post() will handle that internally 
> for you.
> 
> > Http->Post("https://....aspx", pInputXML, pOutputXML);
> > }
> > __finally
> > {
> > delete pOutputXML;
> > }
> 
> If you are not going to use pOutputXML then you don't need to allocate it 
> at all:
> 
> {code}
> Http->Post("https://....aspx", pInputXML, NULL);
> {code}
> 
> Or:
> 
> {code}
> Http->Post("https://....aspx", pInputXML);
> {code}
> 
> > When i try this link i get : „http/1.1 404 not found“
> 
> I already addressed that in my previous reply.  Either you are posting to 
> the wrong URL, or you are being redirected to a non-existant URL.  Is the 
> TIdHTTP::OnRedirect event being triggered?  Or does the TIdHTTP::Response::Location 
> property have a non-blank URL when the error occurs?
> 
> > My Indy version is 10.5.5. Shall i upgrade my version?
> 
> You should consider it, yes.  That is an old version.
> 
> > If yes, how can i do that?
> 
> http://www.indyproject.org/Sockets/Docs/Indy10Installation.EN.aspx
> 
> But even if you don't upgrade, the version you already have should work fine. 
>  I would suggest attaching a TIdLog... component, such as TIdLogFile, to 
> the TIdHTTP::Intercept property, or use the TIdHTTP::ProxyParams property 
> to have TIdHTTP connect to a debugging proxy like Fiddler (http://www.telerik.com/fiddler), 
> so you can see the actual HTTP request/response data going back and forth. 
>  That will give you a better clue about what exactly is going wrong.
> 
> --
> Remy Lebeau (TeamB)

Edited by: Katharina Dorn on Jun 25, 2014 10:19 PM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 26-Jun-2014, at 1:20 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit] [Edit] [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi!

Thank you for your rapidly answer!

> > I need to do that. the company for the I establish the connection told
> > me, that i need to send the Raw XML as part of the post.
> 
> Can you provide the EXACT instructions they gave you?

I request the informations i need i get:   "This is a STD Integration, they just need to place the order and delivery goes through our portal. "


> That is a response from the server.  What does the preceeding request look 
> like?  When you "opened the page", how exactly did you do that?  With a web 
> browser?  That will not POST data, only GET data, unless the web page has 
> an HTML form on it that you are filling out and submitting to the server. 
>  Are you doing that?


I opened the page in my internet explorer for the test.
If i opened the page, its empty.
But its there.
There is no field which can be filled.

But my instructions are i must post the raw xml to the given link...i know nothing more. 

Here are the informations from fiddler:

- Result: 200
- Protocol : HTTPS
- Body : 0
- Caching: private
- Content-type: text/html

Staistics:

The selected session is a HTTP CONNECT Tunnel. This tunnel enables a client to send raw traffic (e.g. HTTPS-encrypted streams or WebSocket messages) through a HTTP Proxy Server (like Fiddler).

Request Count:   1
Bytes Sent:      258		(headers:258; body:0)
Bytes Received:  110		(headers:110; body:0)

ACTUAL PERFORMANCE
--------------
ClientConnected:	07:38:20.264
ClientBeginRequest:	07:38:20.265
GotRequestHeaders:	07:38:20.265
ClientDoneRequest:	07:38:20.265
Determine Gateway:	0ms
DNS Lookup: 		0ms
TCP/IP Connect:	0ms
HTTPS Handshake:	163ms
ServerConnected:	07:38:15.782
FiddlerBeginRequest:	07:38:20.266
ServerGotRequest:	07:38:20.266
ServerBeginResponse:	07:38:20.287
GotResponseHeaders:	07:38:20.287
ServerDoneResponse:	07:38:20.287
ClientBeginResponse:	07:38:20.287
ClientDoneResponse:	07:38:20.287

	Overall Elapsed:	0:00:00.022

RESPONSE BYTES (by Content-Type)
--------------
~headers~: 110


ESTIMATED WORLDWIDE PERFORMANCE
--------------
The following are VERY rough estimates of download times when hitting servers based in Seattle.

US West Coast (Modem - 6KB/sec)
	RTT:		0,10s
	Elapsed:	0,10s

Japan / Northern Europe (Modem)
	RTT:		0,15s
	Elapsed:	0,15s

China (Modem)
	RTT:		0,45s
	Elapsed:	0,45s

US West Coast (DSL - 30KB/sec)
	RTT:		0,10s
	Elapsed:	0,10s

Japan / Northern Europe (DSL)
	RTT:		0,15s
	Elapsed:	0,15s

China (DSL)
	RTT:		0,45s
	Elapsed:	0,45s




HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
SRV: 2
P3P: CP="CAO PSA OUR"
Date: Thu, 26 Jun 2014 05:38:49 GMT
Content-Length: 0

GET https://....aspx HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: de-DE,de;q=0.5
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
DNT: 1
Connection: Keep-Alive

________________
Learn more about HTTP performance at http://fiddler2.com/r/?HTTPPERF

Ps.: If i use this "Http->OnRedirect = &HttpRedirect;"
 i get :Undefiniertes Symbol 'HttpRedirect' --> undefined symbol

 
greetings
_____________________________________________

Edited by: Katharina Dorn on Jun 26, 2014 12:25 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 26-Jun-2014, at 3:25 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi !


I added this to my code.

c++:
	 void __fastcall TFormImportESD::HttpRedirect(TObject *Sender, UnicodeString &dest,
   int &NumRedirect, bool &Handled, UnicodeString &VMethod)
{

	Http->HandleRedirects = true;

}

and in header file.

But nothing changed :(

Shall i consider something?

I changed my code to this:


 std::auto_ptr httpPtr( new TIdHTTP(NULL) );
TIdHTTP *Http = httpPtr.get();
try
{
	TIdSSLIOHandlerSocketOpenSSL *SSL = new TIdSSLIOHandlerSocketOpenSSL(Http );
	Http->IOHandler = SSL;
        Http->IOHandler->Connected();
        Http->HandleRedirects = true;
  	
}
catch( const Exception &e )
{	}

TMemoryStream *pInputXML = new TMemoryStream;

pInputXML->LoadFromFile("C:\\CBUILDER2010.src\\ESD\\PlaceOrder_Request.xml");

pInputXML->Position = 0;

try
{
		Http->OnRedirect;
		Http->Response->Location;
        	Http->Request->Connection = "Keep-Alive";
		TIdHTTPOnRedirectEvent event;
                Http->OnRedirect =  event ;
	        TMemoryStream *pOutputXML = new TMemoryStream;

   try
    {

		Http->ProxyParams->ProxyServer = "127.0.0.1";
		Http->ProxyParams->ProxyPort = 8888;
		Http->Request->ContentType = "text/xml";
		Http->Request->CharSet = "utf-8";
		Http->Request->Accept = "text/html, application/xhtml + xml, */*";
		Http->Request->AcceptEncoding = "gzip, deflate";
		Http->Request->ContentType = "text/html";
        	Http->IOHandler->Host = "localhost";
                Http->Request->Host = "services.....com";
		Http->Connected();
		Http->IOHandler->ConnectTimeout = 60000;
		Http->IOHandler->ReadTimeout = 5000;
		Http->IOHandler->Open();
		Http->IOHandler->Port = 443;
          
		Http->Post("https://........aspx", pInputXML); // error  EIdHTTPProtocolException
	
	  }
	  __finally
	  {
		  Http->IOHandler->Free();
	  }

		
	__finally
	{
		delete pOutputXML;
	}
}
__finally
{
	delete pInputXML;
}


I only tried to use fiddler.
But fiddler brought an error. 
" Content-Length mismatch: Request Header  indicated 914 bytes, but client  sent 0 bytes."

What can i do?

Thank you for your help!

Edited by: Katharina Dorn on Jun 26, 2014 4:14 AM

Edited by: Katharina Dorn on Jun 26, 2014 5:06 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 26-Jun-2014, at 8:07 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit] [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi!

> In any case, the whole point of this OnRedirect exercise was simply to find 
> out if the event is being triggered at all.  If so, what is the value of 
> the 'dest' parameter, 

 - Http->OnRedirect = {NULL, NULL}
 - Where can  i find the Parameter 'dest'? I can't find it in the variable overview. i only found Idtcpclient::TIdTCPClientCustom::FDestination and the value is {NULL}.
 

> and does that URL actually exist on the server?


 - I think so, because my task is to build a connetion to it


> Another way to detect if a redirect is occuring would be to simpy set HandleRedirects 
> to false.  If a redirect happens, TIdHTTP would throw an EIdHTTPProtocolException 
> exception with a 3xx error code.


I added this to my code:


try
{
	TIdSSLIOHandlerSocketOpenSSL *SSL = new TIdSSLIOHandlerSocketOpenSSL(Http );
	Http->IOHandler = SSL;
	//Http->HandleRedirects = true;
	 Http->HandleRedirects = false;
	 Http->ConnectTimeout = 10000; <----
	 Http->ReadTimeout = 10000;<----
}


I changed HandleRedirects to true, i get the error 404. I changed it to false, i get the same error.
With this code i get the 404 error. ( i comment out my Proxy so i avoid the 'Read timed out' Exception.)
When i try a another link from that company, where a code is indicated on the page, i get the code 302. But when i use the link i need i get 404 not found. And in the next step i get Socket Error #0.
It is why i don't set Http->Connect(); ?
When i try this, i need to set a host. But i don't know where and which. 

> That being said, 
> have you tried the TIdLog... alternative yet? 


I took the TIdLogFile Property. I named the File. I searched the file and found it in my EXE directory. But it is empty :(


 
> you are not actually requesting the literal string "https://........aspx", are 
> you?  I assume you are simply masking the URL when posting your code here, 
> correct?


yes it is masked. Because of privacy.



I erased all manually set properties from the TIdHTTP->Request. Its default now.
I only allow Cookies and Handle Redirects. The IOHandler is set to SSL. The defaultport of it is 443. The IPVersion is Id_IPv4. And that's all.
Like my TIdSSLIOHandlerSocketOpenSSL I/O Handler (default port = 443, SSL Option = sslvSSLv23, Mode = sslmClient).


I hope you can help out of the trap (figuratively). :)


greetings!

Edited by: Katharina Dorn on Jun 27, 2014 1:07 AM

Edited by: Katharina Dorn on Jun 27, 2014 1:18 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 27-Jun-2014, at 4:20 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit] [Edit] [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi!


>Did you remember to set the TIdLogFile::Active property to true, like I mentioned 
>earlier? If the file is empty, either the TIdLogFile component was not active, 
>or else TIdHTTP did not transmit/receive any data at all. Since you are 
>getting an HTTP error, clearly data is actually being transmitted. So that 
>makes me think you did not activate the log.


I've set the property to true.
But the file is still empty.


I tried the link with the 302 answer.
I started my program and now i get the content from my dest variable.
The content is "/XML...aspx/.../Login"
Its the page where i can test my xml file. When iam on this page, i manually need to change the URL's (change the 302 URL to the 404 URL) and then i can place the order(manually with klick the button).
Why can i place the order in this way, but it does not work if i call post with the 404 URL? I can't explain it. 
(Ps.: if i manually copy and paste the 404 link in my browser the result is, that the shown page is empty. But there is no error.)


I tested the  Http->Head("https://.....aspx");  method, to check, if the service is responsive. I get the "Read timed out" exception.


Do i need to update my Indy version? Do the program everytime output the Socket error #0 and finish my program or will the program scroll through the code? 
Until now the post command will be executed and then i'll get the socket error and my program ends.
I downloaded the new version from Indy (from http://www.indyproject.org/sockets/download/files/indy10.en.aspx). But its the version 10.0.52. If i'll update my current version with that version i'll downgrade my Indy.
How can i update my version? Can u give me a manual and a link how i can find the right Indy version ?
Currently i ignore this error.
:(

>For example:

>Http->Post("https://hostname/...aspx", ...); // defaults to port 443


>Http->Post("https://hostname:12345/...aspx", ...); // port 12345


Thank you for explanation.




greetings

Edited by: Katharina Dorn on Jun 30, 2014 1:23 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 30-Jun-2014, at 4:26 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit] [Edit] [Edit] [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi!

So now i get only the Socket Error #0 error.
But my order do not arrive.
I think, that my Http Client don't send data.
Is it ok that my UserAgent is "Mozilla/3.0 (compatible; Indy Library)"?



 std::auto_ptr httpPtr( new TIdHTTP(NULL) );

TIdHTTP *Http = httpPtr.get();
 Http->OnRedirect = &HttpRedirect;

try
{
	TIdSSLIOHandlerSocketOpenSSL *SSL = new TIdSSLIOHandlerSocketOpenSSL(Http );
	Http->IOHandler = SSL;
	Http->HandleRedirects = true;
	Http->OnRedirect;
	Http->Response->Location;
	
	 Http->ConnectTimeout = 10000;
	 Http->ReadTimeout = 10000;
}
catch( const Exception &e )
{
  ShowMessage( e.Message );
}


TStringStream *s = new TStringStream;
TMemoryStream *pInputXML = new TMemoryStream;
pInputXML->LoadFromFile("C:\\CBUILDER2010.src\\Project\\xml.xml");
pInputXML->Position = 0;

try{
TMemoryStream *pOutputXML = new TMemoryStream;

	  try
{
	   pInputXML->SaveToStream(s);
	   s->DataString;


	   Http->Post(URL , pInputXML, pOutputXML); //when it reach the post method it takes a couple of seconds and don't walk through
	   pOutputXML->SaveToStream(s);
	   s->DataString;
  }



		  __finally
	  {
		
		  delete pOutputXML;
		  delete pInputXML;

	  }
}




best regards,


Katharina Dorn

Edited by: Katharina Dorn on Jul 1, 2014 4:13 AM

Edited by: Katharina Dorn on Jul 1, 2014 4:49 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 1-Jul-2014, at 7:49 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit] [Edit] [Edit] [Edit] [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi!


I started my program and now the URL get a wrong redirection (detect the wrong host),  post() recognize the wrong host and Fiddler is be ignored. 
The program stop by reach the post(method) and begin at the start. The post method is like a break up.
What's wrong?
Yesterday it redirected right.


best regards

Edited by: Katharina Dorn on Jul 2, 2014 12:01 AM

Edited by: Katharina Dorn on Jul 2, 2014 2:29 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 2-Jul-2014, at 5:31 AM EST
From: Katharina Dorn
 
Re: Http->Post [Edit] [Edit] [Edit] [Edit] [Edit] [Edit]  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi!

> > I started my program and now the URL get a wrong redirection (detect
> > the wrong host),  post() recognize the wrong host
> 
> That is not helpful information.  Please elaborate with an example.

Here is it:



try
{

  Http->ProxyParams->ProxyServer = "127.0.0.1"; // do not work --> Fiddler isn't active ( I started the fiddler program before i run my program)
  Http->ProxyParams->ProxyPort = 8888;// do not work ---> it's not enough to set proxyserver and port. There is no effect. When i use fiddler with google chrome it works fine. But with Embarcadro it doesn't work.
  Http->Request->ContentType = "text/xml";

	std::auto_ptr httpPtr( new TIdHTTP(NULL) );
    TIdHTTP *Http = httpPtr.get();

	Http->IOHandler = new TIdSSLIOHandlerSocketOpenSSL(Http);
	Http->HandleRedirects = true;
	Http->ConnectTimeout = 10000;
                  Http->ReadTimeout = 10000;
	Http->OnRedirect = &HttpRedirect;


    std::auto_ptr pInputXML( new TMemoryStream );
	pInputXML->LoadFromFile("C:\\\CBUILDER2010.src\\\Project\\\xml.xml");
	pInputXML->Position = 0;

	std::auto_ptr pOutputXML( new TMemoryStream );

		Http->Post(Link, pInputXML.get(), pOutputXML.get()); 


}
catch( const Exception &e )
{
	ShowMessage( e.Message );
}




> 
> > The program stop by reach the post(method) and begin at the start. The
> > post method is like a break up.
> 
> I do not understand what you are saying.
> 

When you reach the post() method you will see, that the program stops for a couple of seconds an start at "try" again. It's not run beyond the post() method
That's what i mean.


Ps.: Do you receive my message?

best regards


Katharina Dorn

Edited by: Katharina Dorn on Jul 7, 2014 9:29 PM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 8-Jul-2014, at 12:29 AM EST
From: Katharina Dorn