VBA-tools / VBA-Web

VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web
http://vba-tools.github.io/VBA-Web/
MIT License
2.01k stars 494 forks source link

Conversion PHP #381

Closed AndreaDelCesta closed 5 years ago

AndreaDelCesta commented 5 years ago

I have this PHP code, I would like to convert it to VBA, can you help me?

<?php $url = "https://api.fattureincloud.it:443/v1/clienti/lista"; $request = array( "api_uid" => "", "api_key" => "", "filtro" => "", "id" => "", "nome" => "", "cf" => "", "piva" => "", "pagina" => "1" ); $options = array( "http" => array( "header" => "Content-type: text/json\r\n", "method" => "POST", "content" => json_encode($request) ), ); $context = stream_context_create($options); $result = json_decode(file_get_contents($url, false, $context), true); print_r($result); ?> Best Regards

timhall commented 5 years ago
Dim Client As New WebClient
Client.BaseUrl = "http://www.example.com"

Dim Request As New WebRequest
Request.Resource = "url"
Request.Method = WebMethod.HttpPost
' Request.Format = WebFormat.Json is the default

Dim Body As New Dictionary
Body("api_key") = ""
' ...
Body("pagina") = "1"
Set Request.Body = Body

Dim Response As WebResponse
Set Response = Client.Execute(Request)
' -> POST https://www.example.com/url {"api_key":"",...}

Dim Result As Dictionary ' or Collection for array
Set Result = Response.Data ' automatically parsed response as json

Good luck!