我正在使用Golang 1.4.2(从源代码构建),当我尝试通过http.Client.Do()发出HTTP PUT请求时,请求中缺少Content-Length头.我发送的所有其他标题......我做错了什么?当我通过CURL发出相同的请求时,会发送内容长度标头.我的请求正在向etcd服务器发出,它将我的所有密钥设置为空值.虽然这有点新颖,但几乎没用.:)
http://play.golang.org/p/pIoB--bXUT
package main
import (
"bytes"
"fmt"
"net/http"
"net/http/httputil"
"net/url"
"strconv"
)
func main() {
put := url.Values{}
put.Set("value", "WHOAH here is my stuff")
put.Add("ttl","")
encode := put.Encode()
req, _ := http.NewRequest("PUT", "http://localhost:2379/v2/keys/somekey", bytes.NewBufferString(encode))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Content-Length", strconv.Itoa(len(encode)))
req.Header.Add("X-Content-Length", strconv.Itoa(len(encode)))
dump, _ := httputil.DumpRequest(req, true)
fmt.Println(string(dump))
}
Run Code Online (Sandbox Code Playgroud)
产量
PUT /v2/keys/somekey HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
X-Content-Length: 33
ttl=&value=WHOAH+here+is+my+stuff
Run Code Online (Sandbox Code Playgroud) 我为Magento Enterprise 1.11创建了一个自定义API.通过Soap v1调用API在我的本地开发环境中工作正常,但是我无法从本地环境调用到远程环境.
在我的localdev上使用PHP交互式shell:
php > $client = new SoapClient(WSDL_URI,array('trace'=>1));
php > $client->login(API_USER,API_KEY);
php > var_dump($client->__getLastResponse());
string(538) "<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:loginResponse><loginReturn xsi:type="xsd:string">f0eec73e49665aaf9cc4a6644fba5dc6</loginReturn></ns1:loginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
我已经能够从localhost以及在我的开发机器上运行的两个本地VM之间成功完成此操作.我也可以毫无问题地访问我的自定义API的方法.
但是,当我尝试在我的远程测试环境中创建一个soap客户端时,我能够创建客户端,但是对$ client-> login()或任何后续调用的调用会产生以下结果:
php > $client = new SoapClient(REMOTE_WSDL_URI,array('trace'=>1));
php > $client->login(API_USER,API_KEY);
PHP Warning: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://REMOTE_HOST/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://REMOTE_HOST/index.php/api/index/index/wsdl/1/" in php shell code:1
Stack trace:
#0 php shell code(1): SoapClient->__call('login', Array)
#1 php shell code(1): SoapClient->login(API_USER, API_KEY) …Run Code Online (Sandbox Code Playgroud)