Thread View: borland.public.cppbuilder.internet.web
4 messages
4 total messages
Started by Stephen
Mon, 30 Jul 2007 15:19
IdHTTP Get with XML
Author: Stephen
Date: Mon, 30 Jul 2007 15:19
Date: Mon, 30 Jul 2007 15:19
40 lines
2146 bytes
2146 bytes
I'm attempting to validate addresses and zipcode through the post office's
server.
When I cut and copy the complete url to my web browser, I get a sucessful
verification, but when I attempt to programatically get the data, I fail.
Any pointers and example code would be greatly appreciated it, I'm really
new to this.
The result of my test is "400 Bad request".
My URL is (user ID changed):
http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<?xml
version='1.0'?><AddressValidateRequest USERID='999xxxxx9999'><Address
ID='0'><Address1></Address1><Address2>6406 Ivy
Lane</Address2><City>Greenbelt</City><State>md</State><Zip5>74429</Zip5><Zip4></Zip4></Address></AddressValidateRequest>
My code is:
AnsiString sString = "?API=Verify&XML=<?xml
version='1.0'?><AddressValidateRequest USERID='999xxxxx9999'><Address
ID='0'><Address1></Address1><Address2>6406 Ivy
Lane</Address2><City>Greenbelt</City><State>md</State><Zip5>74429</Zip5><Zip4></Zip4></Address></AddressValidateRequest>";
TIdHTTP* http = new TIdHTTP(Application);
http->Request->ContentType = "text/xml";
TStringStream* outstr = new TStringStream("");
try {
http->Get(sString, outstr);
ShowMessage(outstr->DataString);
}
__finally {
delete outstr;
}
Thank you for any pointers / help
Re: IdHTTP Get with XML
Author: Remy Lebeau (TeamB)
Date: Mon, 30 Jul 2007 17:10
Date: Mon, 30 Jul 2007 17:10
50 lines
2263 bytes
2263 bytes
"Stephen" <susreyNOSPAM.excite.com> wrote in message
news:46ae0187$1@newsgroups.borland.com...
> when I attempt to programatically get the data, I fail.
That is because you are not sending the request correctly, as the server is
telling you.
> My URL is (user ID changed):
<snip>
You should be encoding that URL before passing it to Get().
> My code is:
>
> AnsiString sString = "?API=Verify&XML=<?xml
<snip>
You are not including the full URL address in that string, only the query
portion. You must provide the full URL.
> http->Request->ContentType = "text/xml";
You are sending the XML through the URL itself, not through a post stream,
so the ContentType is meaningless in this case.
Try this instead:
AnsiString sString =
"http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<?xml
version=\"1.0\"?><AddressValidateRequest USERID=\"999xxxxx9999\"><Address
ID=\"0\"><Address1></Address1><Address2>6406 Ivy
Lane</Address2><City>Greenbelt</City><State>md</State><Zip5>74429</Zip5><Zip
4></Zip4></Address></AddressValidateRequest>";
sString = TIdURI::URLEncode(__classid(TIdURI), sString);
TIdHTTP* http = new TIdHTTP(NULL);
try
{
ShowMessage(http->Get(sString));
}
__finally {
delete http;
}
Gambit
Re: IdHTTP Get with XML
Author: Stephen
Date: Mon, 30 Jul 2007 19:21
Date: Mon, 30 Jul 2007 19:21
76 lines
2972 bytes
2972 bytes
Thanks for replying Remy, and I apologize for showing my ignorance. I know
next to nothing about making internet requests.
I've changed the code as you indicated and now get "Connection closed
gracefully" but never get a string (XML) value back. Any idea why? I've
passed a TStringStream as a second parameter. the working portion of my
code now looks like...
TStringStream *out = new TStringStream("");
http->Get(sString, out);
ShowMessage(out->DataString);
but it's crashing right after the get request.
Thanks again Remy.
Stephen
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:46ae1bca$1@newsgroups.borland.com...
>
> "Stephen" <susreyNOSPAM.excite.com> wrote in message
> news:46ae0187$1@newsgroups.borland.com...
>
>> when I attempt to programatically get the data, I fail.
>
> That is because you are not sending the request correctly, as the server
> is
> telling you.
>
>> My URL is (user ID changed):
> <snip>
>
> You should be encoding that URL before passing it to Get().
>
>> My code is:
>>
>> AnsiString sString = "?API=Verify&XML=<?xml
> <snip>
>
> You are not including the full URL address in that string, only the query
> portion. You must provide the full URL.
>
>> http->Request->ContentType = "text/xml";
>
> You are sending the XML through the URL itself, not through a post stream,
> so the ContentType is meaningless in this case.
>
>
> Try this instead:
>
> AnsiString sString =
> "http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<?xml
> version=\"1.0\"?><AddressValidateRequest USERID=\"999xxxxx9999\"><Address
> ID=\"0\"><Address1></Address1><Address2>6406 Ivy
> Lane</Address2><City>Greenbelt</City><State>md</State><Zip5>74429</Zip5><Zip
> 4></Zip4></Address></AddressValidateRequest>";
>
> sString = TIdURI::URLEncode(__classid(TIdURI), sString);
>
> TIdHTTP* http = new TIdHTTP(NULL);
> try
> {
> ShowMessage(http->Get(sString));
> }
> __finally {
> delete http;
> }
>
>
> Gambit
>
>
Re: IdHTTP Get with XML
Author: Stephen
Date: Wed, 01 Aug 2007 21:54
Date: Wed, 01 Aug 2007 21:54
88 lines
3265 bytes
3265 bytes
Any more ideas?
Thanks,
Stephen
"Stephen" <susreyNOSPAM.excite.com> wrote in message
news:46ae3a31$1@newsgroups.borland.com...
> Thanks for replying Remy, and I apologize for showing my ignorance. I
> know next to nothing about making internet requests.
>
> I've changed the code as you indicated and now get "Connection closed
> gracefully" but never get a string (XML) value back. Any idea why? I've
> passed a TStringStream as a second parameter. the working portion of my
> code now looks like...
>
> TStringStream *out = new TStringStream("");
> http->Get(sString, out);
> ShowMessage(out->DataString);
>
> but it's crashing right after the get request.
>
> Thanks again Remy.
>
> Stephen
>
>
>
>
> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
> news:46ae1bca$1@newsgroups.borland.com...
>>
>> "Stephen" <susreyNOSPAM.excite.com> wrote in message
>> news:46ae0187$1@newsgroups.borland.com...
>>
>>> when I attempt to programatically get the data, I fail.
>>
>> That is because you are not sending the request correctly, as the server
>> is
>> telling you.
>>
>>> My URL is (user ID changed):
>> <snip>
>>
>> You should be encoding that URL before passing it to Get().
>>
>>> My code is:
>>>
>>> AnsiString sString = "?API=Verify&XML=<?xml
>> <snip>
>>
>> You are not including the full URL address in that string, only the query
>> portion. You must provide the full URL.
>>
>>> http->Request->ContentType = "text/xml";
>>
>> You are sending the XML through the URL itself, not through a post
>> stream,
>> so the ContentType is meaningless in this case.
>>
>>
>> Try this instead:
>>
>> AnsiString sString =
>> "http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<?xml
>> version=\"1.0\"?><AddressValidateRequest USERID=\"999xxxxx9999\"><Address
>> ID=\"0\"><Address1></Address1><Address2>6406 Ivy
>> Lane</Address2><City>Greenbelt</City><State>md</State><Zip5>74429</Zip5><Zip
>> 4></Zip4></Address></AddressValidateRequest>";
>>
>> sString = TIdURI::URLEncode(__classid(TIdURI), sString);
>>
>> TIdHTTP* http = new TIdHTTP(NULL);
>> try
>> {
>> ShowMessage(http->Get(sString));
>> }
>> __finally {
>> delete http;
>> }
>>
>>
>> Gambit
>>
>>
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads