A cfhttp quot;POSTquot; in php(cfhttp“POST;在php中)
问题描述
我有一个 ColdFusion 页面,它附加了带有表单变量的 URL.我正在尝试在 php 中复制此代码:
I have a ColdFusion page that appends the a URL with form variables. I'm trying replicate this code in php:
<cfhttp method="Post" url='http://api.test.com/import-lead-data.php'>
<cfoutput>
<cfhttpparam name="BAL_ONE" type="formField" value="#BAL_ONE#">
<!--- <cfhttpparam name="MTG_ONE_INT" type="formField" value="#MTG_ONE_INT#">
<cfhttpparam name="MTG_TWO" type="formField" value="#MTG_TWO#">
<cfhttpparam name="BAL_TWO" type="formField" value="#BAL_TWO#">
<cfhttpparam name="ADD_CASH" type="formField" value="#ADD_CASH#">--->
<cfhttpparam name="PRODUCT" type="formField" value="#PRODUCT#">
<cfhttpparam name="PROP_ST" type="formField" value="#PROP_ST#">
<cfhttpparam name="CRED_GRADE" type="formField" value="#CRED_GRADE#">
<cfhttpparam name="PROP_ZIP" type="formField" value="#PROP_ZIP#">
<cfhttpparam name="PROP_DESC" type="formField" value="#PROP_DESC#">
<cfhttpparam name="SPEC_HOME" type="formField" value="#SPEC_HOME#">
<cfhttpparam name="PURCHASE_CONTRACT" type="formField" value="#PURCHASE_CONTRACT#">
<cfhttpparam name="EST_VAL" type="formField" value="#EST_VAL#">
<cfhttpparam name="DOWN_PMT" type="formField" value="#DOWN_PMT#">
<cfhttpparam name="LOAN_TYPE" type="formField" value="#LOAN_TYPE#">
<cfhttpparam name="BUY_TIMEFRAME" type="formField" value="#BUY_TIMEFRAME#">
<cfhttpparam name="AGENT_FOUND" type="formField" value="#AGENT_FOUND#">
<cfhttpparam name="VA_STATUS" type="formField" value="#VA_STATUS#">
<cfhttpparam name="INCOME" type="formField" value="#INCOME#">
<cfhttpparam name="ANNUAL_VERIFIABLE_INCOME" type="formField" value="#ANNUAL_VERIFIABLE_INCOME#">
<cfhttpparam name="FHA_BANK_FORECLOSURE" type="formField" value="#FHA_BANK_FORECLOSURE#">
<cfhttpparam name="NUM_MORTGAGE_LATES" type="formField" value="#NUM_MORTGAGE_LATES#">
<cfhttpparam name="EMAIL" type="formField" value="#EMAIL#">
<cfhttpparam name="FNAME" type="formField" value="#FNAME#">
<cfhttpparam name="LNAME" type="formField" value="#LNAME#">
<cfhttpparam name="ADDRESS" type="formField" value="#ADDRESS#">
<cfhttpparam name="CITY" type="formField" value="#CITY#">
<cfhttpparam name="STATE" type="formField" value="#STATE#">
<cfhttpparam name="ZIP" type="formField" value="#ZIP#">
<cfhttpparam name="PRI_PHON" type="formField" value="#PRI_PHON#">
<cfhttpparam name="SEC_PHON" type="formField" value="#SEC_PHON#">
<cfhttpparam name="CAPTURE_METHOD" type="formField" value="#CAPTURE_METHOD#">
<cfhttpparam name="AID" type="formField" value="#AID#">
<cfhttpparam name="SRLP" type="formField" value="#SRLP#">
<cfhttpparam name="SCid" type="formField" value="#SCid#">
<cfhttpparam name="BUYER_ID" type="formField" value="#BUYER_ID#">
<cfhttpparam name="CID" type="formField" value="#CID#">
<cfhttpparam name="PPCID" type="formField" value="#session.PPCID#">
</cfoutput>
</cfhttp>
我假设我会使用 httpRquest (meth: post)?但我不确定.
I assume I would use a httpRquest (meth: post)? But I'm not sure.
推荐答案
在 PHP HTTP 是集成为所谓的流包装器Docs.这意味着您可以将它与标准文件和流相关的功能一起使用:
In PHP HTTP is intergrated as a so called stream wrapperDocs. That means you can use it with standard file- and stream-related functions:
$url = 'http://api.test.com/import-lead-data.php';
$result = file_get_contents($url);
这将创建一个标准的 GET 请求.但是你想要一个 POST 请求,因此你需要添加一些 上下文选项文档:
This would create a standard GET request. But you want to have a POST request, therefore you need to add some context optionsDocs:
$url = 'http://api.test.com/import-lead-data.php';
$options['http'] = array(
'method' => "POST",
);
$context = stream_context_create($options);
$result = file_get_contents($url, NULL, $context);
这将发出 POST 请求而不是 GET.仍然缺少的是表单字段.假设你有一个键 => 值对数组中的所有字段:
This would make the POST request instead of GET. What's still missing are the form fields. Let's say you have all fields in an array of key => value pairs:
$url = 'http://api.test.com/import-lead-data.php';
$content = http_build_query($form_fields);
$options['http'] = array(
'method' => "POST",
'content' => $content,
);
$context = stream_context_create($options);
$result = file_get_contents($url, NULL, $context);
希望对您有所帮助.当然,您也可以使用 http_post_data
或 http_post_fields
函数(如果有的话).
Hope that's helpful. Naturally you can use as well the http_post_data
or http_post_fields
function as well if you have it available.
参见:HEAD first with PHP Streams.
这篇关于cfhttp“POST";在php中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:cfhttp“POST";在php中
基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01