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

Group A Column Series with WPF Charting Toolkit
Send SMS from phone with bluetooth and C# [closed]
Cleaning thread created by BeginOutputReadLine
How to find a control in a row and bind it to data
NHibernate Tutorial Run-Time Error: HibernateException
Create a dictionary with arrays as values
Going to Marketplace in Trial Mode with an XNA Game
What are the arrows on my mschart
Loading Multiple sheets and exporting to one sheet for excel
How can I search a concatinated string in the where clause of a linqdatasource?
Using fluent NHibernate to map a read only sql view
How to add a random feature for a factory design?
Drawing Text on Image library
C# Byte array assembly
Is it possible to modify an IQueryable expression manually
Is 141 the maximum number of WPF panel items that can be animated simultaneously?

Categories

HOME
asterisk
intellisense
latex
dynamic
ebay-api
magento-1.9.2.1
itext7
redhawksdr
coordinates
sdk
uml-designer
browserstack
google-app-maker
oms
unreal-engine4
adroitlogic
http-status-codes
xmlhttprequest
tracking
brightway
samba
civicrm
novacode-docx
legend-properties
spring-webflow
keystone
polybase
uipath
android-wear-2.0
rollupjs
pydub
visual-studio-community
boosting
emr
javapns
qt-designer
favorites
epub
webspeech-api
matlab-compiler
ansible-inventory
mockserver
jslider
aura-framework
jquery-ui-slider
test-kitchen
ocpjp
togglebutton
activeandroid
gige-sdk
boost-regex
codesniffer
spring-cloud-aws
mac-app-store
dimensionality-reduction
ldd
mrunit
shtml
custom-build-step
abstract
oryx
sqldataadapter
ewam
kramdown
jcomponent
php-gd
winforms-interop
powershell-v1.0
dotcmis
xps
nodeunit
dayofweek
pthreads-win32
carrier
netbeans-plugins
8-puzzle
wordbreaker
gmail-imap
simplemembership
qt5.1
metapost
states
blackberry-eclipse-plugin
aspmenu-control
pdf-reader
django-admin-tools
wxperl
win-prolog
commonsware
zend-validate
rjs
recess
azure-appfabric
datadude

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