li_rc = GetContextService( “Internet”, iinet_base )
IF li_rc < 1 THEN return -1
//parm
lblb_args = blob(postdata,encodingutf8!)
ll_length = len(lblb_args)
ls_header =”Content-Type: ” + &
“application/json~n” + &
“host: “+hostpost + “~n”+&
“Content-Length: ” + String( ll_length ) + “~n~n”
string err[6] = {“-1 General error”,”-2 Invalid URL”,””,”-4 Cannot connect to the Internet”,&
“-5 Unsupported secure (HTTPS) connection attempted”,&
“-6 Internet request failed”}
iinet = create inet
ir = create n_cst_intresult
li_rc =iinet.PostURL(hosturl+”?token=”+posttoken,lblb_args,ls_header,port,ir)
这样写li_rc直接返回-1.之前没有加token时,是ok的。加了这个尾巴就不行。
而接口是否ok呢?用apipost测试是可以的。
不得已改为微软的控件:
//
oleobject ole_http
ole_http = create oleobject
ole_http.ConnectToNewObject( “Msxml2.XMLHTTP”)
ls_url = hosturl+”?token=”+posttoken
//parm
lblb_args = blob(postdata,encodingutf8!)
ll_length = len(lblb_args)
//post
ole_http.Open(“POST”,ls_url,True)
//注意header的写法要分键值对写。和pb的拼接方式不同。
ole_http.setRequestHeader(“Content-Type”,”application/json”)
ole_http.setRequestHeader(“host”,hostpost)
ole_http.setRequestHeader(“Content-Length”,String( ll_length ))
ole_http.Send(lblb_args)
Do While ole_http.readyState <> 4 //查询状态,延时
Yield()
Loop
//获取返回
ir.is_data = ole_http.responseText()
//销毁对象
destroy ole_http
另外之前写了一个get的这个控件的使用。
另外还有一篇是写这个控件的get方法的。需要的话可以在本博客搜索查看。