您好,欢迎访问一九零五行业门户网

php如何调用WebService上传文件

由于我们公司要对oa进行二次开发,oa使用java开发的!现在里面有个接口是上传文件的接口,范例给的是c#的,我又不会c#,php也是新手没玩过接口上传文件,不知道如何动手!
下面附文档说明,看有没大神或版主帮我转成php的语言让我观摩学习下
uploadservice 文件上传服务。
请求路径:/seeyon/uploadservice.do?method= processuploadservice
参数:
token    string   登录验证后获取的身份令牌。   我可以得到
senderloginname  string  发起者登录名         我可以得到
返回值:string
成功则返回生成的附件id,如果多个文件上传则以|符号分割返回
c#范例:
url preurl = null; urlconnection uc = null; preurl = new url(http://xxx.xxx.xxx.xxx/seeyon/uploadservice.do? method = processuploadservice +&senderloginname=+zy +&token=+997a7cdc-2399-47e8-991e-96c859cccc7f); string s = parameters.tostring(); uc = preurl.openconnection(); httpurlconnection hc = (httpurlconnection) uc; hc.setdooutput(true); hc.setusecaches(false); hc.setrequestproperty(contenttype, charset=utf-8); hc.setrequestmethod(post); bufferedinputstream input=new bufferedinputstream(new fileinputstream(c:/ldap集成设计文档.doc)); string boundary = ---------------------------7d4a6d158c9; // 分隔符 string filename=ldap集成设计文档.doc; stringbuffer sb = new stringbuffer(); sb.append(--); sb.append(boundary); sb.append(\r\n); sb.append(content-disposition: form-data; \r\n name=\1\; filename=\+filename+\\r\n); sb.append(content-type: application/msword\r\n\r\n); hc.setrequestproperty(content-type, multipart/form-data;boundary= + ---------------------------7d4a6d158c9); byte[] end_data = (\r\n-- + boundary + --\r\n).getbytes(); dataoutputstream dos = new dataoutputstream(hc.getoutputstream()); dos.write(sb.tostring().getbytes(utf-8)); int cc=0; while((cc=input.read())!=-1) { dos.write(cc); } dos.write(end_data); dos.flush(); dos.close(); fileoutputstream file = new fileoutputstream(c:/test.txt); inputstream is = hc.getinputstream(); int ch; while ((ch = is.read()) != -1) { file.write(ch); } if (is != null) is.close();
回复讨论(解决方案) 搜索 sock文件上传
搜索 sock文件上传
有的人说用curl跟这个有区别吗? 看在100分的份上,求好心人给给代码,不要复制网上的
小弟才接触php不到4个月
从你给出的 c# 代码上看,他和 php 的 sock 文件上传代码是基本一致的
具体的实现有待推敲。
如果服务方遵守标准的 http 协议,用 curl 当然更简单
由于无法得到服务方的反馈,调试是无法进行的
function uploadfiletooa($file=array(),$senderloginname)
{
    $client=new \soapclient(http://xxx.xxx.xxx.xxx/xxx?wsdl);
    $param=array(username=>用户名,password=>密码);
    $token = $client->__soapcall('authenticate',array($param));
    $posturl = http://xxx.xxx.xxx.xxx/xxxloginname.&token=.$token->return->id;
    $fields = array(file=>$file);
    $curl = curl_init($posturl);
    curl_setopt($curl, curlopt_post,true);
    curl_setopt($curl, curlopt_postfields, $fields);
    curl_setopt($curl, curlopt_returntransfer,1);
    $result = curl_exec($curl);
    curl_close($curl);
    return $result;
}
一把辛酸泪,太难了,终于搞定了
其它类似信息

推荐信息