Board index » delphi » Indy http post

Indy http post

Hi all!
Have few questions.
1. As I can see from help Multipart form content for the stream can include
values for the HTML INPUT types:

CHECKBOX
 HIDDEN
 IMAGE
 PASSWORD
 RADIO
 RESET
 SUBMIT
 TEXT
 FILE

should I describe input type in AddField?
2.How.
3. I'm trying post to site which require some checkboxes, selects, file
name, I'm using just AddField and AddFile but getting error "List index out
of bounds(0)"

Indy 9.0.11+BCB6

Thanks for any advice

 

Re:Indy http post


Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3edce75d@newsgroups.borland.com...

Quote
> should I describe input type in AddField?

No.  Simply include the data as "name=value" pairs.  You do not need to
include type names as well.

Quote
> 3. I'm trying post to site which require some
> checkboxes, selects, file name, I'm using just
> AddField and AddFile but getting error "List
> index out of bounds(0)"

What does your actual code look like?  What is the exact line that is
generating the error?

Gambit

Re:Indy http post


AnsiString url;
TIdMultiPartFormDataStream *req=new TIdMultiPartFormDataStream;
IdHTTP1->Request->ContentType=req->RequestContentType;
 req->AddFormField("FileType","SDF");
 req->AddFormField("checkbox2","N");
 req->AddFormField("ListingProgram","sss");
 req->AddFormField("checkbox","Y"); - I hope that's enough ti make checkbox
checked
 req->AddFormField("FType","PR");
 req->AddFile("UploadFileName","c:\\t01.txt","file");
  req->Position=0;

url="https://";
IdHTTP1->Post(url,req);  - here is error

thanks
"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3edceb4b$1@newsgroups.borland.com...

Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3edce75d@newsgroups.borland.com...

Quote
> should I describe input type in AddField?

No.  Simply include the data as "name=value" pairs.  You do not need to
include type names as well.

Quote
> 3. I'm trying post to site which require some
> checkboxes, selects, file name, I'm using just
> AddField and AddFile but getting error "List
> index out of bounds(0)"

What does your actual code look like?  What is the exact line that is
generating the error?

Gambit

Re:Indy http post


Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3edced2b$1@newsgroups.borland.com...

Quote
>  req->AddFormField("checkbox","Y"); - I hope
> that's enough ti make checkbox checked

What does the actual HTML look like that you are trying to mimic?  The names
and values that you supply to AddFormField() must match the exact values
from the HTML.

Gambit

Re:Indy http post


here is page

<form method="POST" enctype="multipart/form-data"
action="/exec/...........">

<input type=hidden name=customer_id value="">

<select name="FileType">
<option selected>Select Your File Type
<option value="TabDelimited">tab delimited
<option value="UIEE">UIEE
<option value="SDF">Standard
</select>

<input type="checkbox" name="checkbox2" value="Y">

<input type="radio" name="ListingProgram" value="Ppp">only<br>
<input type="radio" name="ListingProgram" value="Hhh">and/or<br>
<input type="radio" name="ListingProgram" value="sss">only<br>

<input type="checkbox" name="checkbox" value="Y">

<select name="FType">
<option selected>Select Your Upload Option
<option value="AMD">Add/Modify/Delete
<option value="PR">Purge and Replace
<option value="MD">Modify/Delete
</select>

<input type=image src=https://ssl-images.gif width=80 height=20 border=0>

</form>

"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3edcef20$1@newsgroups.borland.com...

Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3edced2b$1@newsgroups.borland.com...

Quote
>  req->AddFormField("checkbox","Y"); - I hope
> that's enough ti make checkbox checked

What does the actual HTML look like that you are trying to mimic?  The names
and values that you supply to AddFormField() must match the exact values
from the HTML.

Gambit

Re:Indy http post


Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3edcf0c8$1@newsgroups.borland.com...

Quote
> here is page

You're code should be more like this:

    TIdMultiPartFormDataStream *req = new TIdMultiPartFormDataStream;

    reg->AddFormField("customer_id", "");
    req->AddFormField("FileType", "SDF");
    req->AddFormField("checkbox2", "");
    req->AddFormField("ListingProgram", "sss");
    req->AddFormField("checkbox", "Y");
    req->AddFormField("FType", "PR");

    // tweak this URL to suit your actual needs...
    url = "https://www.thedomain.com/exec/...........";

    IdHTTP1->Post(url, req);

The biggest difference I see in this code over your original code is that
you are not specifying the complete URL to post to.  You are only specifying
the protocol portion but no host address or script name at all.  The URL you
post to needs to match the URL from the "action" attribute of the HTML's
<form> element.

Gambit

Re:Indy http post


yeah, actually I'm using real URL, code just has not full URL.
anyway I still have that error even after changes (2 errors in AddFormField)
Thanks
"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3edd0695$1@newsgroups.borland.com...

Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3edcf0c8$1@newsgroups.borland.com...

Quote
> here is page

You're code should be more like this:

    TIdMultiPartFormDataStream *req = new TIdMultiPartFormDataStream;

    reg->AddFormField("customer_id", "");
    req->AddFormField("FileType", "SDF");
    req->AddFormField("checkbox2", "");
    req->AddFormField("ListingProgram", "sss");
    req->AddFormField("checkbox", "Y");
    req->AddFormField("FType", "PR");

    // tweak this URL to suit your actual needs...
    url = "https://www.thedomain.com/exec/...........";

    IdHTTP1->Post(url, req);

The biggest difference I see in this code over your original code is that
you are not specifying the complete URL to post to.  You are only specifying
the protocol portion but no host address or script name at all.  The URL you
post to needs to match the URL from the "action" attribute of the HTML's
<form> element.

Gambit

Re:Indy http post


Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3edd0ec2$1@newsgroups.borland.com...

Quote
> yeah, actually I'm using real URL, code just has not
> full URL. anyway I still have that error even after
> changes (2 errors in AddFormField)

Please create a small sample application that reproduces the problem and
then post the EXACT copy/pasted source code.

Gambit

Re:Indy http post


Sent via mail

"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3edd177b$1@newsgroups.borland.com...

Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3edd0ec2$1@newsgroups.borland.com...

Quote
> yeah, actually I'm using real URL, code just has not
> full URL. anyway I still have that error even after
> changes (2 errors in AddFormField)

Please create a small sample application that reproduces the problem and
then post the EXACT copy/pasted source code.

Gambit

Re:Indy http post


Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3eddf80a@newsgroups.borland.com...

Quote
> Sent via mail

Please post it to the borland.public.attachments group instead.  It does no
good to this group when emailed privately.

Gambit

Re:Indy http post


void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString url,url1;
TIdMultiPartFormDataStream *req=new TIdMultiPartFormDataStream;
IdHTTP1->Request->ContentType=req->RequestContentType;
 req->AddFormField("customer_id","");
 req->AddFormField("FileType","TabDelimitedBooks");
 req->AddFormField("enable-expedited-shipping","");
 req->AddFormField("ListingProgram","PureSDP");
 req->AddFormField("asinate","Y");
 req->AddFormField("FileOperationType","PR");
 req->AddFile("UploadFileName","c:\\booklist01.txt","file");
 req->Position=0;

url="https://secure.amazon.com/exec/panama/seller-admin/catalog-upload/catal
og-asinate/";
IdHTTP1->Post(url,req);
Memo1->Lines->Add(IdHTTP1->ResponseText);

Quote
}

html code
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<html>
<head>
    <style type="text/css"><!--

.serif { font-family: times,serif; font-size: small; }
.sans { font-family: verdana,arial,helvetica,sans-serif; font-size: small; }
.small { font-family: verdana,arial,helvetica,sans-serif; font-size:
x-small; }
.h1 { font-family: verdana,arial,helvetica,sans-serif; color: #CC6600;
font-size: small; }
.h3color { font-family: verdana,arial,helvetica,sans-serif; color: #CC6600;
font-size: x-small; }
.tiny { font-family: verdana,arial,helvetica,sans-serif; font-size:
xx-small; }
.listprice { font-family: arial,verdana,sans-serif; text-decoration:
line-through; font-size: x-small; }
.price { font-family: verdana,arial,helvetica,sans-serif; color: #990000;
font-size: x-small; }

--></style>

<title>
    Upload Your Catalog File Now

</title>

</head>

    <body bgcolor="#FFFFFF" link="#003399" alink="#FF9933" vlink="#996633"
text="#000000">
<a name="top"></a>

<img src="https://ssl-images.amazon.com/images/G/04/icons/amazon-logo.gif"
width=140 height=30>

<br><br>

    <table border=0 cellspacing=0 cellpadding=0>
<tr>

<td valign=middle>
<font face=verdana,arial,helvetica>
<a
href=http://s1.amazon.com/exec/varzea/subst/your-account/manage-your-seller-
account.html/>
Seller Account:

Book Deli</a>

&nbsp;

&gt;&nbsp;&nbsp;<a
href="http://s1.amazon.com/exec/varzea/subst/your-account/upload-items-to-se
ll.html">List Items for Sale</a>&nbsp;&nbsp;

&gt;&nbsp;&nbsp;<b class="h1">Upload Your Book File Now</b><br>&nbsp;&nbsp;

</font>
</td>
</tr>
</table>

    <font face=verdana,arial,helvetica size=-2>

&#40;If you are not Book Deli, <a
href=https://secure.amazon.com/exec/panama/force_login/_p_/seller-admin/cata
log-upload/catalog-asinate/>click here</a> to log in.&#41;
</font>
<br>

<p>
Find your file to upload and review your seller preferences. Then click
Upload Now. Remember you can list in zShops, Amazon Marketplace, or both at
the same time.
<p align="right">

<img src="https://ssl-images.amazon.com/images/G/04/icons/orange-arrow.gif"
width=10 height=9 border=0>

<a href=http://www.amazon.com/exec/obidos/tg/browse/-/562160/>Click here to
review the Book Loader Tutorial</a>.

</p>
<p>
<table width=100% border=0 cellspacing=8 cellpadding=0>

<tr>
<td colspan=2>
<b class="h1">1&#46; Select your file to upload</b><br>
</td>
</tr>
<form method="POST" enctype="multipart/form-data"
action="/exec/panama/seller-admin/catalog-upload/catalog-asinate">
<input type=hidden name=customer_id value="">

<tr><td align=right width=33% valign=top>
<b class="small">Select your file type:</b><br>
</td><td width=66% valign=top align=left>
<select name="FileType">      <option selected>Select Your File Type
<option value="TabDelimited">tab delimited      <option value="UIEE">UIEE
<option value="TabDelimitedBooks">Standard Book      </select>
<p>

<input type="checkbox" name="enable-expedited-shipping" value="Y">

Enable expedited shipping for all listings in this upload--UIEE Sellers
only. (Tab delimited sellers <a
href=http://www.amazon.com/exec/obidos/tg/browse/-/537978/>learn more</a>
about expedited shipping.)

</td></tr>

<tr><td align=right width=33% valign=top>
<b class="small">Select your program:</b>
</td><td width=66% valign=top align=left>
<input type="radio" name="ListingProgram" value="ProMerchant">zShops
only<br>        <input type="radio" name="ListingProgram"
value="HybridSDP">Amazon Marketplace and/or zShops<br>        <input
type="radio" name="ListingProgram" value="PureSDP">Amazon Marketplace
only<br>
&nbsp;&nbsp;&nbsp;
&#40;Selecting this option will only load qualified Marketplace listings.
All other listings will be rejected as errors.&#41;

<p>
<input type="checkbox" name="asinate" value="Y" >

Assign ISBNs automatically for listing in Marketplace &#40;<a
href=http://www.amazon.com/exec/obidos/tg/browse/-/562162/>How does this
work</a>?&#41;

<p>
</td></tr>

<tr><td align=right width=33% valign=top>
<b class="small">Select your upload option&#58;</b><br>
</td><td width=66% valign=top align=left>
<select name="FileOperationType">
<option selected>Select Your Upload Option
<option value="AMD">Add/Modify/Delete
<option value="PR">Purge and Replace
<option value="MD">Modify/Delete
</select><br>
Note&#58; The upload option &#34;Purge and Replace&#34; will purge ALL of
your current Amazon Marketplace and zShop listings and replace them with the
listings contained in your template
<p>
</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Click browse to find your file to upload:</b>
</td><td width=66% valign=top align=left>
<input name="UploadFileName" type="file" size=30>
</td></tr>

<tr>
<td colspan=2>
<hr noshade size=1>
<b class="h1">2&#46; If you are a zShops seller&#44; review your Seller
Preferences</b><br>
<br>
Amazon Marketplace items require set preferences.
<a href=http://www.amazon.com/exec/obidos/tg/browse/-/546270/>Learn why</a>.
You can edit your zShops Seller Preferences by going to your Seller Account
page and clicking Seller Preferences.
</td>
</tr>
<tr><td align=right width=33% valign=top>
<b class="small">Accepted payment methods&#58;</b>
</td><td width=66% valign=top align=left>

Amazon Payments<br>

Money-Order/Cashier's Check<br>

Personal check<br>

</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Online escrow&#58;</b>
</td><td width=66% valign=top align=left>

No

</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Accepted shipping methods&#58;</b>
</td><td width=66% valign=top align=left>

Buyer Pays

</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Location from which your items will be shipped&#58;</b>
</td><td width=66% valign=top align=left>

90025,
Los Angeles, CA

</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Customer Service Policy&#58;</b>
</td><td width=66% valign=top align=left>

N/A

</td></tr>

<tr align="center">
<td colspan=2>
<hr noshade size=1>

<input type=image
src=https://ssl-images.amazon.com/images/G/04/buttons/upload-now.gif
width=80 height=20 border=0>

</td>
</tr>
</form>
</table>

<br clear="all">
<center>

    <br>
<font size=-1>

<a href="http://www.amazon.com/exec/obidos/tg/browse/-/508088/">Conditions
of Use</a>
|
<a href="http://www.amazon.com/exec/obidos/tg/browse/-/468496/">Privacy
Notice</a>

&copy; 1996-2002
Amazon.com, Inc or its affiliates.
</font>

</center>
</body>
</html>

"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3ede448f$1@newsgroups.borland.com...

Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3eddf80a@newsgroups.borland.com...

Quote
> Sent via mail

Please post it to the borland.public.attachments group instead.  It does no
good to this group when emailed privately.

Gambit

Re:Indy http post


yeah in Request few parameters like username, password,
basicauthentication=true

Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3ede4634@newsgroups.borland.com...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString url,url1;
TIdMultiPartFormDataStream *req=new TIdMultiPartFormDataStream;
IdHTTP1->Request->ContentType=req->RequestContentType;
 req->AddFormField("customer_id","");
 req->AddFormField("FileType","TabDelimitedBooks");
 req->AddFormField("enable-expedited-shipping","");
 req->AddFormField("ListingProgram","PureSDP");
 req->AddFormField("asinate","Y");
 req->AddFormField("FileOperationType","PR");
 req->AddFile("UploadFileName","c:\\booklist01.txt","file");
 req->Position=0;

url="https://secure.amazon.com/exec/panama/seller-admin/catalog-upload/catal
og-asinate/";
IdHTTP1->Post(url,req);
Memo1->Lines->Add(IdHTTP1->ResponseText);

Quote
}

html code
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<html>
<head>
    <style type="text/css"><!--

.serif { font-family: times,serif; font-size: small; }
.sans { font-family: verdana,arial,helvetica,sans-serif; font-size: small; }
.small { font-family: verdana,arial,helvetica,sans-serif; font-size:
x-small; }
.h1 { font-family: verdana,arial,helvetica,sans-serif; color: #CC6600;
font-size: small; }
.h3color { font-family: verdana,arial,helvetica,sans-serif; color: #CC6600;
font-size: x-small; }
.tiny { font-family: verdana,arial,helvetica,sans-serif; font-size:
xx-small; }
.listprice { font-family: arial,verdana,sans-serif; text-decoration:
line-through; font-size: x-small; }
.price { font-family: verdana,arial,helvetica,sans-serif; color: #990000;
font-size: x-small; }

--></style>

<title>
    Upload Your Catalog File Now

</title>

</head>

    <body bgcolor="#FFFFFF" link="#003399" alink="#FF9933" vlink="#996633"
text="#000000">
<a name="top"></a>

<img src="https://ssl-images.amazon.com/images/G/04/icons/amazon-logo.gif"
width=140 height=30>

<br><br>

    <table border=0 cellspacing=0 cellpadding=0>
<tr>

<td valign=middle>
<font face=verdana,arial,helvetica>
<a
href=http://s1.amazon.com/exec/varzea/subst/your-account/manage-your-seller-
account.html/>
Seller Account:

Book Deli</a>

&nbsp;

&gt;&nbsp;&nbsp;<a
href="http://s1.amazon.com/exec/varzea/subst/your-account/upload-items-to-se
ll.html">List Items for Sale</a>&nbsp;&nbsp;

&gt;&nbsp;&nbsp;<b class="h1">Upload Your Book File Now</b><br>&nbsp;&nbsp;

</font>
</td>
</tr>
</table>

    <font face=verdana,arial,helvetica size=-2>

&#40;If you are not Book Deli, <a
href=https://secure.amazon.com/exec/panama/force_login/_p_/seller-admin/cata
log-upload/catalog-asinate/>click here</a> to log in.&#41;
</font>
<br>

<p>
Find your file to upload and review your seller preferences. Then click
Upload Now. Remember you can list in zShops, Amazon Marketplace, or both at
the same time.
<p align="right">

<img src="https://ssl-images.amazon.com/images/G/04/icons/orange-arrow.gif"
width=10 height=9 border=0>

<a href=http://www.amazon.com/exec/obidos/tg/browse/-/562160/>Click here to
review the Book Loader Tutorial</a>.

</p>
<p>
<table width=100% border=0 cellspacing=8 cellpadding=0>

<tr>
<td colspan=2>
<b class="h1">1&#46; Select your file to upload</b><br>
</td>
</tr>
<form method="POST" enctype="multipart/form-data"
action="/exec/panama/seller-admin/catalog-upload/catalog-asinate">
<input type=hidden name=customer_id value="">

<tr><td align=right width=33% valign=top>
<b class="small">Select your file type:</b><br>
</td><td width=66% valign=top align=left>
<select name="FileType">      <option selected>Select Your File Type
<option value="TabDelimited">tab delimited      <option value="UIEE">UIEE
<option value="TabDelimitedBooks">Standard Book      </select>
<p>

<input type="checkbox" name="enable-expedited-shipping" value="Y">

Enable expedited shipping for all listings in this upload--UIEE Sellers
only. (Tab delimited sellers <a
href=http://www.amazon.com/exec/obidos/tg/browse/-/537978/>learn more</a>
about expedited shipping.)

</td></tr>

<tr><td align=right width=33% valign=top>
<b class="small">Select your program:</b>
</td><td width=66% valign=top align=left>
<input type="radio" name="ListingProgram" value="ProMerchant">zShops
only<br>        <input type="radio" name="ListingProgram"
value="HybridSDP">Amazon Marketplace and/or zShops<br>        <input
type="radio" name="ListingProgram" value="PureSDP">Amazon Marketplace
only<br>
&nbsp;&nbsp;&nbsp;
&#40;Selecting this option will only load qualified Marketplace listings.
All other listings will be rejected as errors.&#41;

<p>
<input type="checkbox" name="asinate" value="Y" >

Assign ISBNs automatically for listing in Marketplace &#40;<a
href=http://www.amazon.com/exec/obidos/tg/browse/-/562162/>How does this
work</a>?&#41;

<p>
</td></tr>

<tr><td align=right width=33% valign=top>
<b class="small">Select your upload option&#58;</b><br>
</td><td width=66% valign=top align=left>
<select name="FileOperationType">
<option selected>Select Your Upload Option
<option value="AMD">Add/Modify/Delete
<option value="PR">Purge and Replace
<option value="MD">Modify/Delete
</select><br>
Note&#58; The upload option &#34;Purge and Replace&#34; will purge ALL of
your current Amazon Marketplace and zShop listings and replace them with the
listings contained in your template
<p>
</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Click browse to find your file to upload:</b>
</td><td width=66% valign=top align=left>
<input name="UploadFileName" type="file" size=30>
</td></tr>

<tr>
<td colspan=2>
<hr noshade size=1>
<b class="h1">2&#46; If you are a zShops seller&#44; review your Seller
Preferences</b><br>
<br>
Amazon Marketplace items require set preferences.
<a href=http://www.amazon.com/exec/obidos/tg/browse/-/546270/>Learn why</a>.
You can edit your zShops Seller Preferences by going to your Seller Account
page and clicking Seller Preferences.
</td>
</tr>
<tr><td align=right width=33% valign=top>
<b class="small">Accepted payment methods&#58;</b>
</td><td width=66% valign=top align=left>

Amazon Payments<br>

Money-Order/Cashier's Check<br>

Personal check<br>

</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Online escrow&#58;</b>
</td><td width=66% valign=top align=left>

No

</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Accepted shipping methods&#58;</b>
</td><td width=66% valign=top align=left>

Buyer Pays

</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Location from which your items will be shipped&#58;</b>
</td><td width=66% valign=top align=left>

90025,
Los Angeles, CA

</td></tr>
<tr><td align=right width=33% valign=top>
<b class="small">Customer Service Policy&#58;</b>
</td><td width=66% valign=top align=left>

N/A

</td></tr>

<tr align="center">
<td colspan=2>
<hr noshade size=1>

<input type=image
src=https://ssl-images.amazon.com/images/G/04/buttons/upload-now.gif
width=80 height=20 border=0>

</td>
</tr>
</form>
</table>

<br clear="all">
<center>

    <br>
<font size=-1>

<a href="http://www.amazon.com/exec/obidos/tg/browse/-/508088/">Conditions
of Use</a>
|
<a href="http://www.amazon.com/exec/obidos/tg/browse/-/468496/">Privacy
Notice</a>

&copy; 1996-2002
Amazon.com, Inc or its affiliates.
</font>

</center>
</body>
</html>

"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3ede448f$1@newsgroups.borland.com...

Quote
"BOBAH" <bo...@softhome.net> wrote in message

news:3eddf80a@newsgroups.borland.com...

Quote
> Sent via mail

Please post it to the borland.public.attachments group instead.  It does no
good to this group when emailed privately.

Gambit

Other Threads