使用curl向asp.net页面提交Post数据 用curl来提交数据但是没有效果想问一下 需要如何实现这个功能asp中表单:<form name="form1" method="post" action="index-cs.aspx" id="form1" enctype="multipart/form-data"></form>是否需要伪造个头信息?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、你只给了一个空表单。谁知道需要提交什么?2、表单有 enctype 属性,应该是有文件上传的3、你没有给出提交的 php 代码,让人如何帮助你 stream_context_create的方式:<?php function do_post_request($url, $postdata, $files = null) { $data = ""; $boundary = "---------------------".substr(md5(rand(0,32000)), 0, 10); //Collect Postdata foreach($postdata as $key => $val) { $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; } $data .= "--$boundary\n"; //Collect Filedata foreach($files as $key => $file) { $fileContents = file_get_contents($file['tmp_name']); $data .= "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file['name']}\"\n"; $data .= "Content-Type: image/jpeg\n"; $data .= "Content-Transfer-Encoding: binary\n\n"; $data .= $fileContents."\n"; $data .= "--$boundary--\n"; } $params = array('http' => array( 'method' => 'POST', 'header' => 'Content-Type: multipart/form-data; boundary='.$boundary, 'content' => $data )); $ctx = stream_context_create($params); $fp = fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } //set data (in this example from post) //sample data $postdata = array( 'name' => $_POST['name'], 'age' => $_POST['age'], 'sex' => $_POST['sex'] ); //sample image $files['image'] = $_FILES['image']; do_post_request("http://example.com", $postdata, $files); ?>或者通过CURL的这个参数:CURLOPT_POSTFIELDS 全部数据使用HTTP协议中的"POST"操作来发送。要发送文件,在文件名前面加上@前缀并使用完整路径。这个参数可以通过urlencoded后的字符串类似'para1=val1¶2=val2&...'或使用一个以字段名为键值,字段数据为值的数组。如果value是一个数组,Content-Type头将会被设置成multipart/form-data。 [[email protected] htdocs]$ php curl.php Array( [file] => Array ( [name] => log.txt [type] => application/octet-stream [tmp_name] => /tmp/phpSak15H [error] => 0 [size] => 4 ))Array( [sub] => this is submit)[[email protected] htdocs]$ cat curl.php <?php$curl = curl_init('http://localhost:8500/upload.php');curl_setopt($curl, CURLOPT_POST, true);curl_setopt($curl, CURLOPT_POSTFIELDS, array('sub' => 'this is submit', 'file' => '@/home/liangdong/libs/htdocs/log.txt'));curl_exec($curl);?>[[email protected] htdocs]$ cat upload.html <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /></head><body><form method="post" action="upload.php" enctype="multipart/form-data"> <input type="file" name="upload" /> <input type="submit" name="sub" /></form></body></html> php如何读取xml中的值 最土团购程序购物车功能开发完毕【散分】 COM("WScript.Shell") 求php怎么调用含BLOB存储过程 下了段PHP源码研究,可是核心文件加密了,看看有谁知道这是什么加密方式么 svn自动跟新程序 我是一个新手,希望大家多多帮忙!! wordpress 固定连接设置问题 微信公众号高级接口客服消息 如何获取图片所在页面的url discuz x2.5 子版块太多,想做个分页 dede plus模板页如何调用arclist标签
2、表单有 enctype 属性,应该是有文件上传的
3、你没有给出提交的 php 代码,让人如何帮助你
function do_post_request($url, $postdata, $files = null)
{
$data = "";
$boundary = "---------------------".substr(md5(rand(0,32000)), 0, 10);
//Collect Postdata
foreach($postdata as $key => $val)
{
$data .= "--$boundary\n";
$data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n";
}
$data .= "--$boundary\n";
//Collect Filedata
foreach($files as $key => $file)
{
$fileContents = file_get_contents($file['tmp_name']);
$data .= "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file['name']}\"\n";
$data .= "Content-Type: image/jpeg\n";
$data .= "Content-Transfer-Encoding: binary\n\n";
$data .= $fileContents."\n";
$data .= "--$boundary--\n";
}
$params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary='.$boundary,
'content' => $data
)); $ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
} //set data (in this example from post) //sample data
$postdata = array(
'name' => $_POST['name'],
'age' => $_POST['age'],
'sex' => $_POST['sex']
); //sample image
$files['image'] = $_FILES['image']; do_post_request("http://example.com", $postdata, $files);
?>或者通过CURL的这个参数:
CURLOPT_POSTFIELDS 全部数据使用HTTP协议中的"POST"操作来发送。要发送文件,在文件名前面加上@前缀并使用完整路径。这个参数可以通过urlencoded后的字符串类似'para1=val1¶2=val2&...'或使用一个以字段名为键值,字段数据为值的数组。如果value是一个数组,Content-Type头将会被设置成multipart/form-data。
Array
(
[file] => Array
(
[name] => log.txt
[type] => application/octet-stream
[tmp_name] => /tmp/phpSak15H
[error] => 0
[size] => 4
))
Array
(
[sub] => this is submit
)
[[email protected] htdocs]$ cat curl.php
<?php
$curl = curl_init('http://localhost:8500/upload.php');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, array('sub' => 'this is submit', 'file' => '@/home/liangdong/libs/htdocs/log.txt'));
curl_exec($curl);
?>
[[email protected] htdocs]$ cat upload.html
<html>
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /></head>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="file" name="upload" />
<input type="submit" name="sub" />
</form>
</body>
</html>