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#, How Do I Get Mono Configured on Windows Powershell (Windows 10)? (Environmental Variable PATH)
UTF-8 Byte Mark check gives different value based on operating system
C# - Packet being sent but client not receiving it
C# AES Base64 Encryption (on Strings)
C# custom object invalid cast [closed]
Why a Bit value from SQL Server can't get converted to a C# bool through my DataSet.Designer?
What's the WPF equivalent of a Winform ToolStripContainer?
C# static constructor in instance class — Pros & Contras
C# ASCX Module DataGrid doesn’t show values to 2 decimal places from MySQL-Workbench database table
Addition of values in datagridview c#
on button click display a label
Cannot implicitly convert type 'product
How load strings from JSON file to .resw file in UWP
How to serialize a list of list
how to debug MSBuild dependency issues?
How do I pass a parameter from a querystring to a component registration in Autofac?

Categories

HOME
system-calls
intellij-idea
openacc
dynamic
readdir
jquery-plugins
hiveql
sugarcrm
liquidsoap
open-search-server
oms
aws-sdk-cpp
jetbrains
element
luis
game-engine
android-actionbar
indri
beacon
openoffice-basic
fibonacci
multipart
wai-aria
onclicklistener
advertising
ppp
mongoose-im
checkmarx
emr
azure-table-storage
federated
folder
vtd-xml
deferred
login-required
webspeech-api
traitsui
machine-code
hippocms
cowboy
file-conversion
datagridviewcombobox
vpython
qt-quick
gradlew
encoder
text-formatting
rivets.js
skype-bots
perldoc
ajv
pyautogui
portaudio
mongodb-3.3
jspx
boost-range
xcode7.1
recurring
sprockets
diameter-protocol
django-celery
aws-kms
pebble-js
wizard
jsondoc
askbot
event-tracking
taverna
windows-phone-8-emulator
uinavigationitem
jsoncpp
litedb
web-standards
fileinputstream
stderr
chrome-mobile
mri
optimistic-locking
qxorm
alpha-beta-pruning
system.io.packaging
tigase
parsefloat
new-operator
codio
randomaccessfile
grunt-contrib-imagemin
mysql2
pageload
system.transactions
setcookie
openafs
hypertable
filedialog
nsscrollview
mvcmailer
clgeocoder
session-hijacking
nstoolbar
jquery-attributes
miniport
silverlight-2.0
for-xml
morfik
paperless

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