PHP代码转换器到VB.NET [英] Php code converter to VB.NET
本文介绍了PHP代码转换器到VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在vb.net中编写下面的php代码。有人可以帮助我吗?
是否有任何代码转换器从php到vb.net?
I need to write the below php code in in vb.net .Can somebody help me?
Is there any code converter from php to vb.net?
<?php
/**
* Function to fetch access token
*/
function get_token($userName, $userPassword) {
//init the url
$Url = "http://api.abcdtesting.net/json/token";
//encapsulate the credentials into a base64 string
$authString = base64_encode($userName . ":" . $userPassword);
//init header array
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization:' . $authString;
//init curl api and send request - returning $data
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
//process response - return token or assert error
if (curl_errno($ch)) {
echo 'error:' . curl_error($ch) . '<br/>';
curl_close($ch);
return '';
} else {
//token valid
$tk = json_decode($data, true);
curl_close($ch);
return $tk[0]['token'];
}
}
我的尝试:
What I have tried:
I need to write the below php code in in vb.net .Can somebody help me?
Is there any code converter from php to vb.net?
<pre><?php
/**
* Function to fetch access token
*/
function get_token($userName, $userPassword) {
//init the url
$Url = "http://api.abcdtesting.net/json/token";
//encapsulate the credentials into a base64 string
$authString = base64_encode($userName . ":" . $userPassword);
//init header array
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization:' . $authString;
//init curl api and send request - returning $data
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
//process response - return token or assert error
if (curl_errno($ch)) {
echo 'error:' . curl_error($ch) . '<br/>';
curl_close($ch);
return '';
} else {
//token valid
$tk = json_decode($data, true);
curl_close($ch);
return $tk[0]['token'];
}
}
推荐答案
userName,
userPassword){
//初始化网址
userPassword) { //init the url
Url =http://api.abcdtesting.net/json/token;
//将凭证封装到base64字符串
Url = "http://api.abcdtesting.net/json/token"; //encapsulate the credentials into a base64 string
这篇关于PHP代码转换器到VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文