Solved

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

Posted on 2014-09-17
2
524 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

685 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