using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Windows.Forms;
namespace InvoicingTool
{
public class PostDataHelper
{
///
/// POST本地数据至服务器
///
/// 服务器URL地址
/// POST数据包
/// 返回服务器响应结果
public static string HttpPost(string Url, string postDataStr, Boolean isServerpart = false)
{
string retString = "";
if (isServerpart)
{
QualityHelper _QualityHelper = new QualityHelper();
string _strServiceURL = String.Format("http://{0}:{1}/service.asmx", _QualityHelper.dbip, _QualityHelper.serviceport);
//_strServviceURL = "http://localhost:7080/MobilePayService/Service.asmx";
//Url = "http://localhost:8010/MobileServicePlatform/Handler/handler_ajax.ashx";
object[] _args = { Url, postDataStr };
try
{
retString = WSHelper.InvokeWebService(_strServiceURL, "UploadSeller", _args).ToString();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
else
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = Encoding.UTF8.GetBytes(postDataStr);
request.ContentLength = byteArray.Length;
try
{
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
using (WebResponse response = request.GetResponse())
{
using (Stream dataStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(dataStream))
{
string responseFromServer = reader.ReadToEnd();
retString = responseFromServer;
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
return retString;
}
}
}