Solved

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

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

747 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