Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;',
Posted
Comments
Afzaal Ahmad Zeeshan 20-May-18 7:37am    
They both handle the HTTP communication, so you need to understand how one works in order to rewrite it in another framework or language.

Start from this thread, it has an example.
raza4444 21-May-18 7:26am    
thanx for response . Actually I know about php curl(http communication).This php curl is working mode(tested).It just need to convert it in asp.net. But I am new in asp.net . I also know the method of send http request method in asp.net . But issue is that I am not getting proper thing to resolve this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900