473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

how to create multipart HTTP request using HttpWebRequest

Hi,

I need to create a multipart request to UPS manifest upload electronic
service. UPS wants the request to consist of a series of headers and
bodies, and its not clear how can I use the HttpWebRequest object to do
this. there is the Headers collection, but I don't think it will give
me the control we need.

is there a low-level way to create the entire stream and attach to the
object before posting ?

this is the requirement for the request from UPS: notice it has the
first header, specifying Multipart and a boundry defined by the work
BOUNDRY.with a total length of 1040

then you have the first boundry, with length=140, the actual content
for this boundry, then another boundry ...

============================================
POST /hapld/tos/kdwhapltos HTTP/1.1<cr/lf>
Host: www.pld-certify.ups.com<cr/lf>
Content-type: multipart/mixed; boundary=BOUNDARY<cr/lf>
Content-length: 1040<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-www-form-urlencoded<cr/lf>
Content-length: 140<cr/lf>
<cr/lf>
AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&Respo nseType=application/x-ups-pld&VersionNumber=
V4R1&UserId=useridvalue&Password=passwordvalue<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-ups-binary<cr/lf>
Content-length: 719<cr/lf>
<cr/lf>
020082 2.0 2002101700000000000010500 000000001*AA0A1754 US
1234567002000001*BA1z1234560100002352 00001+0000000000000010 +000
0000000000000LBS01PRE10 3INUSD000001*CA18ATTENTION
DELIVERY 234 SOME LOCAL ST SO
ME CITY NJ 07652 US12015551212 *PA1z1234560100002352
02+0000010 +0000010
*SA000004<cr/lf>
<cr/lf>
--BOUNDARY--<cr/lf>

Jan 11 '07 #1
4 5295
Hello,

have you tried to set the HttpWebRequest.SendChunked to true?

Best regards,
Henning Krause

<yo**********@structuredweb.comwrote in message
news:11*********************@p59g2000hsd.googlegro ups.com...
Hi,

I need to create a multipart request to UPS manifest upload electronic
service. UPS wants the request to consist of a series of headers and
bodies, and its not clear how can I use the HttpWebRequest object to do
this. there is the Headers collection, but I don't think it will give
me the control we need.

is there a low-level way to create the entire stream and attach to the
object before posting ?

this is the requirement for the request from UPS: notice it has the
first header, specifying Multipart and a boundry defined by the work
BOUNDRY.with a total length of 1040

then you have the first boundry, with length=140, the actual content
for this boundry, then another boundry ...

============================================
POST /hapld/tos/kdwhapltos HTTP/1.1<cr/lf>
Host: www.pld-certify.ups.com<cr/lf>
Content-type: multipart/mixed; boundary=BOUNDARY<cr/lf>
Content-length: 1040<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-www-form-urlencoded<cr/lf>
Content-length: 140<cr/lf>
<cr/lf>
AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&Respo nseType=application/x-ups-pld&VersionNumber=
V4R1&UserId=useridvalue&Password=passwordvalue<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-ups-binary<cr/lf>
Content-length: 719<cr/lf>
<cr/lf>
020082 2.0 2002101700000000000010500 000000001*AA0A1754 US
1234567002000001*BA1z1234560100002352 00001+0000000000000010 +000
0000000000000LBS01PRE10 3INUSD000001*CA18ATTENTION
DELIVERY 234 SOME LOCAL ST SO
ME CITY NJ 07652 US12015551212 *PA1z1234560100002352
02+0000010 +0000010
*SA000004<cr/lf>
<cr/lf>
--BOUNDARY--<cr/lf>
Jan 11 '07 #2
thanks for the answer!

how would SendChunked alter the control over the request ? it seems
only relevant to allow breaking of large requests into multiple, but no
fine control over logical sections, which is what I need.

there seems to be no support for Multipart with this class. do you
think I can create only the top-level headers, and then prepare
everything else as one content, including the second "content-type" and
"content-length" sections ?

Henning Krause [MVP - Exchange] wrote:
Hello,

have you tried to set the HttpWebRequest.SendChunked to true?

Best regards,
Henning Krause

<yo**********@structuredweb.comwrote in message
news:11*********************@p59g2000hsd.googlegro ups.com...
Hi,

I need to create a multipart request to UPS manifest upload electronic
service. UPS wants the request to consist of a series of headers and
bodies, and its not clear how can I use the HttpWebRequest object to do
this. there is the Headers collection, but I don't think it will give
me the control we need.

is there a low-level way to create the entire stream and attach to the
object before posting ?

this is the requirement for the request from UPS: notice it has the
first header, specifying Multipart and a boundry defined by the work
BOUNDRY.with a total length of 1040

then you have the first boundry, with length=140, the actual content
for this boundry, then another boundry ...

============================================
POST /hapld/tos/kdwhapltos HTTP/1.1<cr/lf>
Host: www.pld-certify.ups.com<cr/lf>
Content-type: multipart/mixed; boundary=BOUNDARY<cr/lf>
Content-length: 1040<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-www-form-urlencoded<cr/lf>
Content-length: 140<cr/lf>
<cr/lf>
AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&Respo nseType=application/x-ups-pld&VersionNumber=
V4R1&UserId=useridvalue&Password=passwordvalue<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-ups-binary<cr/lf>
Content-length: 719<cr/lf>
<cr/lf>
020082 2.0 2002101700000000000010500 000000001*AA0A1754 US
1234567002000001*BA1z1234560100002352 00001+0000000000000010 +000
0000000000000LBS01PRE10 3INUSD000001*CA18ATTENTION
DELIVERY 234 SOME LOCAL ST SO
ME CITY NJ 07652 US12015551212 *PA1z1234560100002352
02+0000010 +0000010
*SA000004<cr/lf>
<cr/lf>
--BOUNDARY--<cr/lf>
Jan 11 '07 #3
Hello,

I would guess, yes.
As for the SendChunked - If set to true, the data is automatically sent in
chunks as per RFC 2616
(http://www.w3.org/Protocols/rfc2616/...html#sec3.6.1).
But you can't control the chunksize here...

Best regards,
Henning Krause

<yo**********@structuredweb.comwrote in message
news:11*********************@k58g2000hse.googlegro ups.com...
thanks for the answer!

how would SendChunked alter the control over the request ? it seems
only relevant to allow breaking of large requests into multiple, but no
fine control over logical sections, which is what I need.

there seems to be no support for Multipart with this class. do you
think I can create only the top-level headers, and then prepare
everything else as one content, including the second "content-type" and
"content-length" sections ?

Henning Krause [MVP - Exchange] wrote:
>Hello,

have you tried to set the HttpWebRequest.SendChunked to true?

Best regards,
Henning Krause

<yo**********@structuredweb.comwrote in message
news:11*********************@p59g2000hsd.googlegr oups.com...
Hi,

I need to create a multipart request to UPS manifest upload electronic
service. UPS wants the request to consist of a series of headers and
bodies, and its not clear how can I use the HttpWebRequest object to do
this. there is the Headers collection, but I don't think it will give
me the control we need.

is there a low-level way to create the entire stream and attach to the
object before posting ?

this is the requirement for the request from UPS: notice it has the
first header, specifying Multipart and a boundry defined by the work
BOUNDRY.with a total length of 1040

then you have the first boundry, with length=140, the actual content
for this boundry, then another boundry ...

============================================
POST /hapld/tos/kdwhapltos HTTP/1.1<cr/lf>
Host: www.pld-certify.ups.com<cr/lf>
Content-type: multipart/mixed; boundary=BOUNDARY<cr/lf>
Content-length: 1040<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-www-form-urlencoded<cr/lf>
Content-length: 140<cr/lf>
<cr/lf>
AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&Respo nseType=application/x-ups-pld&VersionNumber=
V4R1&UserId=useridvalue&Password=passwordvalue<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-ups-binary<cr/lf>
Content-length: 719<cr/lf>
<cr/lf>
020082 2.0 2002101700000000000010500 000000001*AA0A1754 US
1234567002000001*BA1z1234560100002352 00001+0000000000000010 +000
0000000000000LBS01PRE10 3INUSD000001*CA18ATTENTION
DELIVERY 234 SOME LOCAL ST SO
ME CITY NJ 07652 US12015551212 *PA1z1234560100002352
02+0000010 +0000010
*SA000004<cr/lf>
<cr/lf>
--BOUNDARY--<cr/lf>
Jan 11 '07 #4

its actually working! I create one long string that contains all the
secondary boundries , each with its own content-type and content-length
headers. most of the complexity stems from having to calculate the
total length to put in the initial content-length header. I wonder if
this is a specific UPS requirement or part of the protocol RFC, but oh
well, it can't hurt and its working!

the trick is to add correctly the lengths of al the various parts so
the content-length

Henning Krause [MVP - Exchange] wrote:
Hello,

I would guess, yes.
As for the SendChunked - If set to true, the data is automatically sent in
chunks as per RFC 2616
(http://www.w3.org/Protocols/rfc2616/...html#sec3.6.1).
But you can't control the chunksize here...

Best regards,
Henning Krause

<yo**********@structuredweb.comwrote in message
news:11*********************@k58g2000hse.googlegro ups.com...
thanks for the answer!

how would SendChunked alter the control over the request ? it seems
only relevant to allow breaking of large requests into multiple, but no
fine control over logical sections, which is what I need.

there seems to be no support for Multipart with this class. do you
think I can create only the top-level headers, and then prepare
everything else as one content, including the second "content-type" and
"content-length" sections ?

Henning Krause [MVP - Exchange] wrote:
Hello,

have you tried to set the HttpWebRequest.SendChunked to true?

Best regards,
Henning Krause

<yo**********@structuredweb.comwrote in message
news:11*********************@p59g2000hsd.googlegro ups.com...
Hi,

I need to create a multipart request to UPS manifest upload electronic
service. UPS wants the request to consist of a series of headers and
bodies, and its not clear how can I use the HttpWebRequest object to do
this. there is the Headers collection, but I don't think it will give
me the control we need.

is there a low-level way to create the entire stream and attach to the
object before posting ?

this is the requirement for the request from UPS: notice it has the
first header, specifying Multipart and a boundry defined by the work
BOUNDRY.with a total length of 1040

then you have the first boundry, with length=140, the actual content
for this boundry, then another boundry ...

============================================
POST /hapld/tos/kdwhapltos HTTP/1.1<cr/lf>
Host: www.pld-certify.ups.com<cr/lf>
Content-type: multipart/mixed; boundary=BOUNDARY<cr/lf>
Content-length: 1040<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-www-form-urlencoded<cr/lf>
Content-length: 140<cr/lf>
<cr/lf>
AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&Respo nseType=application/x-ups-pld&VersionNumber=
V4R1&UserId=useridvalue&Password=passwordvalue<cr/lf>
<cr/lf>
--BOUNDARY<cr/lf>
Content-type: application/x-ups-binary<cr/lf>
Content-length: 719<cr/lf>
<cr/lf>
020082 2.0 2002101700000000000010500 000000001*AA0A1754 US
1234567002000001*BA1z1234560100002352 00001+0000000000000010 +000
0000000000000LBS01PRE10 3INUSD000001*CA18ATTENTION
DELIVERY 234 SOME LOCAL ST SO
ME CITY NJ 07652 US12015551212 *PA1z1234560100002352
02+0000010 +0000010
*SA000004<cr/lf>
<cr/lf>
--BOUNDARY--<cr/lf>
Jan 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: darin dimitrov | last post by:
I am looking for an implementation of a multipart content parser for ..NET (http://www.faqs.org/rfcs/rfc2388.html). I suppose that the HttpWebRequest class uses such a parser in order to extract...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
3
by: NextOne | last post by:
Hi ! Is it possible to send an AJAX XMLHttpRequest using prototype.js API for a multipart/form-data ? I already done parsing form parameters and sending GET/POST request, but does this work...
4
by: Bob | last post by:
I've got to use the http protocol to communicate with another machine as part of a Web Service using HttpWebRequest and HttpWebResponse. As such, timing is important. When I create the...
0
by: Luis Esteban Valencia | last post by:
Hello. I got this message <ns0:Orden xmlns:ns0="http://localhost/CreditCheck"> <IdCliente>10</IdCliente> - <Pedido> <IdProducto>IdProducto_0</IdProducto> <Cantidad>10.4</Cantidad>...
3
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to create a call to a web page to validate and register software. The code I'm using is: Private Sub OK_Click(ByVal sender As...
6
by: Boldgeek | last post by:
I am trying to develop an app that will allow automatic updating of a web form which uses multipart/form-data enctype (as it MIGHT be sending an image) I have an example form, which when...
0
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or...
2
by: karthickdevi | last post by:
Hi, I am developing a Desktop Application in VB .Net to upload files to the server. I need to encrypt the contents and upload it to the server. I am supposed to use enctype=multipart/form-data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.