c#


Multiple Part Http Post Request C#


I'll try to explain this as best as possible, I'm new to webservices/requests in C#.
Using WebClient, I've created a request with multiple header values. Along with these values, an image (.dat) file has to be sent along with the request. I am unable to do so. For a better idea here is my code:
Console.WriteLine("Beginning SendRequest!");
string img = System.IO.File.ReadAllText(#"\\[SERVER NAME]\mages\Images\" + imgNum + ".dat");
ChequeData imgdata = new Data();
helpers help = new helpers();
imgdata = help.getData(data);
WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("Content-Type", "application/octet-stream");
myWebClient.Headers.Add("PTC_TIMESTAMP", date);
// there are 10 more Headers.Add() which hold private information
// add the image to the request
Console.Write("Resulting Request Headers: ");
Console.WriteLine(myWebClient.Headers.ToString());
byte[] byteArray = Encoding.ASCII.GetBytes(PTC_SERVER);
// Upload the input string using POST
byte[] responseArray = myWebClient.UploadData(PTC_SERVER, "POST", byteArray);
// Upload the file to the URI.
// The 'UploadFile(uriString,fileName)' method implicitly uses HTTP POST method.
byte[] fileArray = myWebClient.UploadFile(PTC_SERVER, img);
// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file uploaded are:\n{0}",
System.Text.Encoding.ASCII.GetString(fileArray));
// Decode and display the response.
Console.WriteLine("\nResponse with IMG received was {0}",
Encoding.ASCII.GetString(responseArray));
Console.WriteLine("Waiting for 10 seconds..");
System.Threading.Thread.Sleep(10000);
Console.WriteLine("End of SendRequest!");

Related Links

C# Win Form Spell Checker .Net 3.5
How to localize string, that not used in form elements
Session and databases preference
Wait for event handlers to complete before continuing
FluentNHibernate unidirectional many-to-many association
.NET 4 equivalent of Task.WhenAll()
Find a control's row number in an HTML table
Is there a way to constrain a type parameter to SqlDbType?
Using wildcards with a LinqDataSource
SMTPClient class error
Why does my GridView switch out of Edit mode?
Why is NHibernate giving me the error “could not resolve property: of: Customers”
linq-to-sql grouping anonymous type
Adding a WPF namespace causes VSTO compile error
Image.FromFile starts 'skipping' files
Launching JAR with Process.Start: javaw.exe runs but “nothing happens”?

Categories

HOME
actionscript-3
excel-formula
botframework
marie
intellij-idea
jquery-plugins
coordinates
xss
powerquery
aggregate-functions
autocad
scapy
google-api-oauth
annyang
subprocess
ios-universal-links
ldap-query
browsermob
box2d
css-float
web-parts
geography
google-street-view
gpo
webgl-earth
rancher
inspec
windows-mobile
visual-studio-community
jms-topic
recreate
delphi-2010
arp
textview
jql
spring-oauth2
restler
mkdir
border-layout
perf
sdl-2
bootstrap-carousel
servicebus
ocpjp
angular-fullstack
encoder
spring-ide
text-formatting
remap
evaluation
flask-socketio
jcs
cancan
iban
cedar-bdd
firebase-polymer
easy68k
magick.net
aws-kms
phpdesigner
fadein
instabug
self-join
data-representation
httpmodule
chrome-mobile
data-quality-services
sony-xperia
qxorm
novell
nsnotificationcenter
nest-initiative
serializer
banana-pi
sigma-grid-control
pidgin
nodeunit
new-operator
xcode6.1-gm-seed
misfire-instruction
fade
cab
static-class
objectdatasource
nokogiri
gwt2
blotter
boost.build
rfc822
motordriver
openafs
flatten
ruby-1.9
cgaffinetransform
symfony-1.2
lgpl
chars
for-xml
jgrowl

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App