Solved

Send data using Post method from asp.net to EPOS Device

Posted on 2014-09-17
2
514 Views
Last Modified: 2014-09-22
Hello Experts,
My aim is to send data to the EPOS device from asp.net page when requested. I am having following code

string URLAuth = "http://xyz.com/FarmerUpload.aspx";
  string postString = string.Format("inputEmailHandle={0}&name={1}&inputPassword={2}", FarmerCode, FarmerData);

  const string contentType = "application/x-www-form-urlencoded";
  System.Net.ServicePointManager.Expect100Continue = false;

  CookieContainer cookies = new CookieContainer();
  HttpWebRequest webRequest = WebRequest.Create(URLAuth) as HttpWebRequest;
  webRequest.Method = "POST";
  webRequest.ContentType = contentType;
  webRequest.CookieContainer = cookies;
  webRequest.ContentLength = postString.Length;
  webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
 webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  webRequest.Referer = "http://xyz.com/FarmerUpload.aspx";

Open in new window


But I am unable to send data to the EPOS Device (This device is configured to receive the data in POST method only)
I am able to get the data sent from EPOS device using query string. Based on that I need to send the data.
0
Comment
Question by:Manoj Patil
2 Comments
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 40327661
There are some flaws. First of all your post data string containes three placeholders, but you're only providing two values. Then you don't execute the post.

This could work:

const string POST_DATA = "inputEmailHandle={0}&name={1}&inputPassword={2}";
const string REFERER = "http://xyz.com/FarmerUpload.aspx";
const string URL = "http://xyz.com/FarmerUpload.aspx";

WebRequest request = WebRequest.Create(URL);
request.Method = "POST";            
string postData = string.Format(POST_DATA, FarmerCode, FarmerData);
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.Referer = REFERER;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();

Console.WriteLine(((HttpWebResponse)response).StatusDescription);

dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();

Open in new window

0
 
LVL 19

Author Closing Comment

by:Manoj Patil
ID: 40338354
Thanks.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now