Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial WinInet模拟HTTP的POST请求出错

WinInet模拟HTTP的POST请求出错

Jun 23, 2016 pm 01:55 PM
http post Error simulation ask

在VS2012里面设置断点跟踪执行,发现请求该php文件获取的不是正确的返回字串,而是如下出错信息:

Invalid query: 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Whole query: 
select id,name from index_activities where top=0

这段信息是我在PHP的

$result = mysql_query($query);
Copy after login

语句行后面,“if”请求不成功才输出的,显然是mysql请求没成功,且可以确定,调用该PHP文件是成功的。

但是当我在网页中用同样的参数调用同一个PHP文件时(GET方式),返回值则是正确的。

我php文件中获取传参是用的
$top = $_REQUEST['top'];
Copy after login

所以POST和GET参数应该都可以同样获取的。

不知道可能是哪里出了问题?用WinInet传参会造成这个请求字串有什么异常吗?


回复讨论(解决方案)

数据库连接正确吗?

数据库连接正确吗?


连接正确啊,不正确就返回unable to connect to mysql了,就不会执行到下面的请求,也不会出现MySQL的请求出错信息了。

另有一个同样的模拟HTTP请求,也有参数,返回就是正确的:

void CDllValidateDlg::ValidateAPerson(char* Name, char* Code){	CString post_data;	post_data.Format("userid='%s'&name='%s'",Code,Name); //请求的附加参数	CString result; //返回的结果	CString post_page = "test_id_validater/validateid.php"; //请求的php	PostHttpPage(result,post_page,post_data);	AfxMessageBox(result);}
Copy after login

而我现在调试不明白的这个HTTP请求,到底哪里不一样,我把原本由变量决定的参数都写死了,仍然返回说mysql请求不正确:
void CDllValidateDlg::getActs(HTREEITEM root){	CString post_data="top=0";//	char top[10];//	itoa(ActivitiesTree.GetItemData(root),top,10);//	post_data.Format("top=%s",top);	CString result;	CString post_page = "test_id_validater/GetActivities.php";//	AfxMessageBox("post_page:"+post_page+", "+"post_data:"+post_data);	PostHttpPage(result, post_page, post_data);	AfxMessageBox(result);    ……    ……
Copy after login

感觉好像是PHP端的问题,像下面这么写就返回正确了:

<?phprequire "use_daoru.php";$top = $_REQUEST['top'];$query = "select id,name from index_activities where top=0";$result = mysql_query($query);//if(!$result){//$message = 'Invalid query: '.mysql_error()."\n";//$message.= 'Whole query: '.$query;//die($message);//}$num = mysql_num_rows($result);for($i=0;$i<$num;$i++){	$row = mysql_fetch_row($result);	echo($row[0].":".$row[1].",");}?>
Copy after login

原来我写的代码是:
<?phprequire "use_daoru.php";$top = $_REQUEST['top'];$query = "select id,name from index_activities where top=$top";$result = mysql_query($query);//if(!$result){//$message = 'Invalid query: '.mysql_error()."\n";//$message.= 'Whole query: '.$query;//die($message);//}$num = mysql_num_rows($result);for($i=0;$i<$num;$i++){	$row = mysql_fetch_row($result);	echo($row[0].":".$row[1].",");}?>
Copy after login

Invalid query: 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Whole query: 
select id,name from index_activities where top=0
这个信息分明是数据库报的错!

如果 $query = "select id,name from index_activities where top=0"; 可以
而 $query = "select id,name from index_activities where top=$top"; 不可以
这就表示 $top 无值或不是数字

$top = $_REQUEST['top']; 改为  $top = intval($_REQUEST['top']); 试试

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

HTTP 200 OK: Understand the meaning and purpose of a successful response HTTP 200 OK: Understand the meaning and purpose of a successful response Dec 26, 2023 am 10:25 AM

HTTP Status Code 200: Explore the Meaning and Purpose of Successful Responses HTTP status codes are numeric codes used to indicate the status of a server's response. Among them, status code 200 indicates that the request has been successfully processed by the server. This article will explore the specific meaning and use of HTTP status code 200. First, let us understand the classification of HTTP status codes. Status codes are divided into five categories, namely 1xx, 2xx, 3xx, 4xx and 5xx. Among them, 2xx indicates a successful response. And 200 is the most common status code in 2xx

http request 415 error solution http request 415 error solution Nov 14, 2023 am 10:49 AM

Solution: 1. Check the Content-Type in the request header; 2. Check the data format in the request body; 3. Use the appropriate encoding format; 4. Use the appropriate request method; 5. Check the server-side support.

How to implement HTTP streaming using C++? How to implement HTTP streaming using C++? May 31, 2024 am 11:06 AM

How to implement HTTP streaming in C++? Create an SSL stream socket using Boost.Asio and the asiohttps client library. Connect to the server and send an HTTP request. Receive HTTP response headers and print them. Receives the HTTP response body and prints it.

How to implement PHP to jump to the page and carry POST data How to implement PHP to jump to the page and carry POST data Mar 22, 2024 am 10:42 AM

PHP is a programming language widely used in website development, and page jumps and carrying POST data are common requirements in website development. This article will introduce how to implement PHP page jump and carry POST data, including specific code examples. In PHP, page jumps are generally implemented through the header function. If you need to carry POST data during the jump process, you can do it through the following steps: First, create a page containing a form, where the user fills in the information and clicks the submit button. Acti in the form

What status code is returned for an HTTP request timeout? What status code is returned for an HTTP request timeout? Feb 18, 2024 pm 01:58 PM

The HTTP request times out, and the server often returns the 504GatewayTimeout status code. This status code indicates that when the server executes a request, it still fails to obtain the resources required for the request or complete the processing of the request after a period of time. It is a status code of the 5xx series, which indicates that the server has encountered a temporary problem or overload, resulting in the inability to correctly handle the client's request. In the HTTP protocol, various status codes have specific meanings and uses, and the 504 status code is used to indicate request timeout issues. in customer

PHP code example: How to use POST to pass parameters and implement page jumps PHP code example: How to use POST to pass parameters and implement page jumps Mar 07, 2024 pm 01:45 PM

Title: PHP code example: How to use POST to pass parameters and implement page jumps In web development, it often involves the need to pass parameters through POST and process them on the server side to implement page jumps. PHP, as a popular server-side scripting language, provides a wealth of functions and syntax to achieve this purpose. The following will introduce how to use PHP to implement this function through a practical example. First, we need to prepare two pages, one to receive POST requests and process parameters

See all articles