Home > Net >  Post the return value is a bit strange to PHP
Post the return value is a bit strange to PHP

Time:01-24

 
Public static string Post (url string, the string content)
{
The string result="";
HttpWebRequest the req=(HttpWebRequest) WebRequest. Create (url);
The req. Method="POST";
The req. ContentType="application/x - WWW - form - urlencoded";

# region add Post parameter
Byte [] data=https://bbs.csdn.net/topics/Encoding.UTF8.GetBytes (content);
The req. ContentLength=data. Length;
Using (Stream reqStream=the req. GetRequestStream ())
{
ReqStream. Write (data, 0, the data Length);
ReqStream. Close ();
}
# endregion

HttpWebResponse resp=(HttpWebResponse) the req. The method GetResponse ();
The Stream Stream=resp. GetResponseStream ();
//get response content
Using (StreamReader reader=new StreamReader (stream, Encoding UTF8))
{
Result=reader. ReadToEnd ();
}
return result;
}


 


<meta charset="utf-8" & gt;


<body>

Test: & lt; Input type="text" name="fname" & gt;






 
<? PHP
Print_r ($_POST [] "fname");
?>





Is fill in the content on the web page, which is submitted may be normal in the browser to display content, but in c # using methods after submitted in the past, even the interface page to print out, ask bosses give directions which is wrong, thanks for bosses

CodePudding user response:

What do you value parameter c # travels? And your submission and response are written in this way, what's the logic

CodePudding user response:

The results from the response, what do you via HTTP post request the post. PHP, this result is in line with expectations of normal results, but also a bit of a problem,
Don't know what is the purpose of you, look at the post. PHP and welcome. PHP:
1. Post. PHP is text/HTML mime, and access to a post. The PHP page should use is a GET request (but you use the post), now that you request a HTML, natural in the expected returns an HTML page,
2. If you need to access the welcome. PHP, then take the parameters directly request welcome. PHP, in this case, the post. The PHP and c # code you do the same things, are equivalent, likewise, F12, directly in the console $. Post ("/welcome. PHP "... ) this is the third method to do the same thing,

Among this logic need you to review your own needs, what do you want to be 1, 2, or want to do

CodePudding user response:

If I didn't say clearly, so to understand:
1. Open a browser, access to a post. PHP;
2. Fill out the form, submit, jump to the welcome. PHP,
During the whole process, there are two actions of using c # to do:
1. HTTP get request post. PHP, that is, what are you doing now (best to HTTP get);
2. The HTTP post welcome. PHP, is expected to do, you think they have done, actually did not do,
Of course, if really to handle in c #, step 1 is superfluous,

CodePudding user response:

Another may be a problem, your c # interface is an HTTP get request of interface, the ginseng, whether it's url, or preparing to welcome. The content of the PHP, is likely to be escaped, lead to send welcome. PHP content change, avoid this problem can use url_encode, or directly change the c # interface to [httppost]
  •  Tags:  
  • C#
  • Related