DalSoft / DalSoft.RestClient

The C# REST Client - the only REST/ HTTP Client you will ever need
https://restclient.dalsoft.io
MIT License
217 stars 43 forks source link

Trailing slash after .php address #61

Closed otapi closed 5 years ago

otapi commented 5 years ago

I need to reach a server via .php address - like on the RestClientTest example e.g.: http://en.directupload.net/index.php.

Simplify the example a bit:

dynamic client = new RestClient("http://en.directupload.net/index.php");  

var result = client.Query(new {
                param = "stuff"
                }).Get().Result;

The problem is that the constructed RequestUri has an unnecessary slash after the .php, like this: http://en.directupload.net/index.php/?param=stuff Therefore the PHP server doesn't understand the query :( How can remove that extra slash?

DalSoft commented 5 years ago

Does it work as below? It should because index.php is the default document.

dynamic client = new RestClient("http://en.directupload.net");
var result = client.Query(new
{
   param = "stuff"
}).Get().Result

Let me know how you get on and if you need anything else.

otapi commented 5 years ago

No, the server what I need to reach doesn't use the default index.php, it uses a different name (getitem.php).

DalSoft commented 5 years ago

Sorry I misunderstood for resources that would result in invalid C# syntax use the Resource method.

dynamic restClient = new RestClient("https://myserver.com/");          
var result = await restClient.Resource("getitem.php").Query( new {  param = "stuff" } ).Get();

I've re-tested this just in case of a bug, but it works correctly and calls https://myserver.com/getitem.php?param=stuff

https://restclient.dalsoft.io/docs/how-to-access-resources/ Has more information.

otapi commented 5 years ago

This works, thank you!