Jump to content
  • 0

how to start with API ...


AriusII

Question

Hello,
I have a fix ip with port open ect ... ( 80 - 5400 ) 
I have my Intersect Server ( IS * ) on my windows deskop ( 192.168.0.10  [ Api : http://localhost:5400 ] )
My webserver is hosted by my BOX in a ubuntu VM ( 192.168.0.180 )

@jcsnider say me to go : here https://stackoverflow.com/questions/6213509/send-json-post-using-php

I followed the two average solution, and one with CURL, but, it dosn't work...

i creat an oauth.php 
 

Quote

<?PHP
$url = "http://192.168.0.10:5400/api/oauth/token";
$data = array
(
    'grant_type' => 'password',
    'username' => 'AriusII',
    'password' => '3964E32D361C9E6F1813196A25D2BA5E2BE435146588FAAAE09E58EAB704239D'
);
$content = json_encode($data);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 201 ) {
    die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}


curl_close($curl);

$response = json_decode($json_response, true);
?>

 

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 1

Undo the changes to your PHP file. Change the line back to:

$url = "http://192.168.0.10:5400/api/oauth/token";

 

 

Edit your server api config file, change the hostname to:

  "Hosts": [
    "http://*:5400"
  ],

 

Run your server as administrator so windows will allow it to bind that port, if it gives you an error change the port to 5402.

 

It should work after that.

Link to comment
Share on other sites

  • 1
12 minutes ago, jcsnider said:

Undo the changes to your PHP file. Change the line back to:

$url = "http://192.168.0.10:5400/api/oauth/token";

 

 

Edit your server api config file, change the hostname to:

  "Hosts": [
    "http://*:5400"
  ],

 

Run your server as administrator so windows will allow it to bind that port, if it gives you an error change the port to 5402.

 

It should work after that.


£Yeah ! It's that i don't have thinked about a Port conflict ! THANKS

Link to comment
Share on other sites

  • 0
Quote

{
  "RouteAuthorization": {},
  "Hosts": [
    "http://localhost:5400"
  ],
  "Cors": [],
  "DataProtectionKey": "EA478F6EA89DFDC752B29460A2E0B42D05AA6D6D65EBC35A38426D0EEACE8D79",
  "Enabled": true,
  "DebugMode": false,
  "SeedMode": false,
  "RefreshTokenLifetime": 15
}



I only have one account, and yeah he have the APi Right ( with the api account true )

Link to comment
Share on other sites

  • 0

it's don't work and when i edit my ' localhost:5400 ' ( it'sm y 192.168.0.10 )
and edit it with my external ip ( 82.64.190.33:5400)

Failed to start API.
2020-02-12 21:32:32.504 [Error] Failed to start API.
System.Reflection.TargetInvocationException: Une exception a été levée par la cible d'un appel. ---> System.Net.HttpListenerException: Accès refusé
   à System.Net.HttpListener.AddAllPrefixes()
   à System.Net.HttpListener.Start()
   à Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener listener, Func`2 appFunc, IList`1 addresses, IDictionary`2 capabilities, Func`2 loggerFactory)
   à Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(Func`2 app, IDictionary`2 properties)
   --- Fin de la trace de la pile d'exception interne ---
   à System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   à System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   à Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder builder)
   à Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
   à Intersect.Server.Web.RestApi.RestApi.Start() dans C:\Users\JC Snider\Desktop\AGD\Intersect-Engine\Intersect.Server\Web\RestApi\RestApi.cs:ligne 71

Link to comment
Share on other sites

×
×
  • Create New...