如何在ASP.NET中转换PHP curl(httpwebrequest) [英] How do convert PHP curl in ASP.NET (httpwebrequest )

查看:89
本文介绍了如何在ASP.NET中转换PHP curl(httpwebrequest)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将这个php curl转换为asp.net。我是asp.net的初学者,有人可以帮助我将这个卷曲转换为asp.net。请 。 

$ handle = curl_init();
if($ this-> accessToken){
//访问令牌用于OAuth2流
$ url。='?access_token ='。 $这 - >的accessToken;
}否则if($ this-> token){
// Auth令牌来自PG账户
$ url。='?auth_token ='。 $这 - >令牌;
} else {
//如果使用用户名和密码 - 将它们作为curl选项传递
curl_setopt($ handle,CURLOPT_USERPWD,$ this-> username。':'。$ this-> ;密码);
}
curl_setopt($ handle,CURLOPT_URL,$ url);
curl_setopt($ handle,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ handle,CURLOPT_CUSTOMREQUEST,strtoupper($ method));
curl_setopt($ handle,CURLOPT_HTTPHEADER,array(
'Content-type:multipart / form-data;',
));

//如果请求有其他选项 - 将它们添加到请求
if(!empty($ options)){

//提取文件,单独传递
$ files = array();
foreach($ options as $ key => $ value){
if(!empty($ value)&&!is_array($ value)&& $ value [0] = =='@'){
$ files [$ key] = $ this-> toCurlFile($ value);
未设置($ options [$ key]);
}
}
$ data = $ files;
if(!empty($ options)){
//原始API要求数据为json格式
$ data = array_merge($ data,array(
'data') => json_encode($ options),
));
}
curl_setopt($ handle,CURLOPT_POSTFIELDS,$ data);
}
$ response = curl_exec($ handle);





我尝试过:



我试图在asp.net中使用httpwebrequest转换它。但鉴于下面的PHP线令我困惑。这就是原因,我无法开始这项工作来转换它在asp.net。 
curl_setopt($ handle,CURLOPT_URL,$ url);
curl_setopt($ handle,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ handle,CURLOPT_CUSTOMREQUEST,strtoupper($ method));
curl_setopt($ handle,CURLOPT_HTTPHEADER,数组(
'内容类型:multipart / form-data;',

解决方案

handle = curl_init();
if(


this-> accessToken){
//访问令牌用于OAuth2流程

url。='?access_token ='。


I want to convert this php curl into asp.net . I am a beginner in asp.net , can someone here help me to convert this curl into asp.net. please . 

$handle = curl_init();
if ($this->accessToken) {
            // Access token is used in OAuth2 flow
            $url .= '?access_token=' . $this->accessToken;
        } else if ($this->token) {
            // Auth token is taken from PG account
            $url .= '?auth_token=' . $this->token;
        } else {
            // if using username and password - pass them as curl option
            curl_setopt($handle, CURLOPT_USERPWD, $this->username . ':' . $this->password);
        }
        curl_setopt($handle, CURLOPT_URL, $url);
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($handle, CURLOPT_CUSTOMREQUEST, strtoupper($method));
        curl_setopt($handle, CURLOPT_HTTPHEADER, array(
            'Content-type: multipart/form-data;',
        ));

        // if request has additional options - add them to request
        if (! empty($options)) {

            // extract files, pass them separately
            $files = array();
            foreach ($options as $key => $value) {
                if (! empty($value) && ! is_array($value) && $value[0] === '@') {
                    $files[$key] = $this->toCurlFile($value);
                    unset($options[$key]);
                }
            }
  $data = $files;
            if (! empty($options)) {
                // original API requires data to be in json format
                $data = array_merge($data, array(
                    'data' => json_encode($options),
                ));
            }
            curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
        }
        $response = curl_exec($handle);



What I have tried:

I have tried to convert this using httpwebrequest in asp.net . but given below line of php confusing me. that is the reason , I am not able to  start this work to convert it in asp.net. 
curl_setopt($handle, CURLOPT_URL, $url);
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($handle, CURLOPT_CUSTOMREQUEST, strtoupper($method));
        curl_setopt($handle, CURLOPT_HTTPHEADER, array(
            'Content-type: multipart/form-data;',

解决方案

handle = curl_init(); if (


this->accessToken) { // Access token is used in OAuth2 flow


url .= '?access_token=' .


这篇关于如何在ASP.NET中转换PHP curl(httpwebrequest)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆