PDA

View Full Version : مشکل در : ارسال اطلاعات به صفحه وب از روش پست



wilyfox
یک شنبه 17 اسفند 1393, 19:45 عصر
سلام.میخوام یه درخواست رو به یه صفحه وب بفرستم و جواب اونو بگیرم .ولی اررور میده .وقتی با html تست کردم درست کار میکرد و لی با برنامه نمیشه.:

این سورس کد :

using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Charge_Viewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


public string SendPost(string url, string postData)
{
string webpageContent = string.Empty;


try
{
byte[] byteArray = Encoding.UTF8.GetBytes(postData);


HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;


using (Stream webpageStream = webRequest.GetRequestStream())
{
webpageStream.Write(byteArray, 0, byteArray.Length);
}


using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
{
webpageContent = reader.ReadToEnd();
}
}
}
catch (Exception ex)
{
//throw or return an appropriate response/exception
}


return webpageContent;
}


private void Form1_Load(object sender, EventArgs e)
{
string a = SendPost("http://accounting.hamyar.net/IBSng/user/", "normal_username=****&normal_password=*****");
MessageBox.Show(a);
}
}
}




و اینم اررور :


---------------------------

---------------------------
<br />
<b>Fatal error</b>: Call to undefined function http_response_code() in <b>/usr/local/IBSng/interface/IBSng/inc/auth.php</b> on line <b>138</b><br />


---------------------------
OK
---------------------------

username و password رو پاک کردم.

mreram
یک شنبه 17 اسفند 1393, 21:30 عصر
سلام اینطور که به نظر میرسه خطا سمت php هست ...
ولی این کد رو من تست کردم جواب داد...
byte[] data=new byte[1024];
string str= "normal_username=****&normal_password=*****";
data = Encoding.UTF8.GetBytes(str);
HttpWebRequest httpwebrequest =(HttpWebRequest) WebRequest.Create("http://accounting.hamyar.net/IBSng/user/");
httpwebrequest.Method = "post";
httpwebrequest.ContentType = "application/x-www-form-urlencoded";
using(Stream s=httpwebrequest.GetRequestStream())
{
s.Write(data,0,data.Length);
}

using (HttpWebResponse httpweb = (HttpWebResponse)httpwebrequest.GetResponse())
{
using (StreamReader sr = new StreamReader(httpweb.GetResponseStream()))
{
label1.Text = sr.ReadToEnd();
}
}

mreram
یک شنبه 17 اسفند 1393, 21:34 عصر
با متد get هم میدونم که این آدرس رو میفرستی بهت جواب میده
http://accounting.hamyar.net/IBSng/user/?normal_username=****&normal_password=*****

wilyfox
دوشنبه 18 اسفند 1393, 11:35 صبح
ممنون.
الان یه مشکل دیگه هست .
وقتی با متد get صفحه رو دانلود میکنم باز هم همون اررور رو میده.انگار کوکی ها و سیشن ها رو موقع انتقال به صفحه بعدی نمیبره.
در اصل من میخوام صفحه http://accounting.hamyar.net/IBSng/user/home.php رو ذخیره کنم که فرم ورود و صفحه اکشنش http://accounting.hamyar.net/IBSng/user است.

mreram
دوشنبه 18 اسفند 1393, 16:52 عصر
ممنون.
الان یه مشکل دیگه هست .
وقتی با متد get صفحه رو دانلود میکنم باز هم همون اررور رو میده.انگار کوکی ها و سیشن ها رو موقع انتقال به صفحه بعدی نمیبره.
در اصل من میخوام صفحه http://accounting.hamyar.net/IBSng/user/home.php رو ذخیره کنم که فرم ورود و صفحه اکشنش http://accounting.hamyar.net/IBSng/user است.
بله خب کوکی ها و سشن ها با مرورگر کار میکنن برای اینکار از این کد استفاده کنید:


webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36";
webRequest.Host = "http://accounting.hamyar.net/IBSng/user";
webRequest.Referer = "http://accounting.hamyar.net/ (http://accounting.hamyar.net/IBSng/user)/ (http://sms.high-net.in/)";