Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-09-17
2
Medium Priority
?
549 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
ste5an earned 2000 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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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