2017-02-28 19:46
浏览 96

C#/ JSON转换为PHP脚本

I need to extract data from a website's REST api, but I've never worked with it, and I'm just getting back into coding again after some time. But I need to get this project moving in a forward direction very quickly, and cannot for the life of me, figure out how to convert this C#/JSON string into a php equivalent script to poll for the data I need...

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(address);
httpWebRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}",UserName, Password))));

I'm thinking I need to use curl for this, but again, it's been a long time, and I'm a little rusty. Any help is greatly appreciated.

图片转代码服务由CSDN问答提供 功能建议

我需要从网站的REST api中提取数据,但我从来没有使用它,我是 一段时间后再次重新编码。 但是我需要让这个项目很快向前移动,并且不能为我的生活,找出如何将这个C#/ JSON字符串转换为PHP等效脚本来轮询我需要的数据......

  HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(address); 
httpWebRequest.Headers.Add(“Authorization”,“Basic”+ Convert.ToBase64String(System.Text.ASCIIEncoding。  ASCII.GetBytes(string.Format(“{0}:{1}”,UserName,Password)))); 

我想我需要 为此使用卷曲,但是,这已经很长一段时间了,我有点生疏了。 非常感谢任何帮助。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongluobei9359 2017-02-28 19:49

    You can go ahead and try to use cUrl which is used to make calls with the different to an API.

    There is also this library which is based on cUrl. and some samples from the site.

    //For making a GET request
    $curl = new Curl();
    //For making a POST request
    $curl = new Curl();
    $curl->post('', array(
      'username' => 'myusername',
      'password' => 'mypassword',
    //With custom headers
    $curl = new Curl();
    $curl->setBasicAuthentication('username', 'password');
    点赞 打赏 评论
  • doufud21086 2017-02-28 20:57

    Simple way with $_GET['pass'], $_GET['user']

    WebClient webClient = new WebClient();
    webClient.Encoding = Encoding.UTF8;
    response = webClient.DownloadString("");
    点赞 打赏 评论

相关推荐 更多相似问题