我正在使用网络服务(由于保密,我无法透露姓名).在获取wsdl页面之前,Web服务要求我使用用户名和密码登录.例如,如果我在Web服务器中输入服务URL,则会提示我输入登录信息.
所以,我假设需要首先验证自己,然后使用wsdl.
但是,我写了一些测试代码,这些代码消耗了w3schools Celsius到Fahrenheit服务,它不需要身份验证并且工作正常.
<!--- soap request in xml --->
<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://www.w3schools.com/webservices/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<SOAP-ENV:Body>
<tns:CelsiusToFahrenheit xmlns:tns="http://www.w3schools.com/webservices/">
<tns:Celsius>34</tns:Celsius>
</tns:CelsiusToFahrenheit>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</cfsavecontent>
<!---Sending a post request accessing the defined SOAPAction CelsiusToFahrenheit--->
<cfhttp url="http://www.w3schools.com/webservices/tempconvert.asmx" method="post" result="httpresponse">
<cfhttpparam type="header" name="content-type" value="text/xml">
<cfhttpparam type="header" name="SOAPAction" value="""http://www.w3schools.com/webservices/CelsiusToFahrenheit""">
<cfhttpparam type="header" name="content-length" value="#len(soap)#">
<cfhttpparam type="header" name="charset" value="utf-8">
<cfhttpparam type="xml" name="message" value="#trim(soap)#">
</cfhttp>
<!---Output the result if http status is 200 …Run Code Online (Sandbox Code Playgroud) 我在Linux Mint过去几周一直在学习C语言.但是,我切换到OSX并测试了这段代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *arr = calloc(10, sizeof(int));
if(arr == NULL)
printf("arr is null");
for(int i = 0; i < 10; i++, arr++){
printf("%d \n", *arr);
}
free(arr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这应该工作并打印10个零,它会这样做,但它不会释放arr.
这是输出:
0
0
0
0
0
0
0
0
0
0
a.out(532,0x7fff72606300) malloc: *** error for object 0x7ff060c04b48: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
Run Code Online (Sandbox Code Playgroud)
我不明白我如何访问未分配的内存.如果没有分配arr,输出不应该是"arr为空"吗?