• I am creating an endpoint in my blog, to do a server to server communication with a third party api, the endpoint works, the data arrives in my endpoint, but I did not find ways to trigger this third endpoint that I need for php, I tried wp_remote_post, http, curl, and none of the alteratives happens sending to the external endpoint, I pasted the code in the gist, if someone can give me a help in what I may be missing, because I can not see any solution to this.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Is the request sent to meusistema.com this third endpoint you are trying to use? Any HTTP request sent by any means available should work. Not all servers have cURL, but it’s a good option if available. I would suggest you use one of the WP_Http class methods.

    It’s puzzling that other methods do not work. Are you sure your dispatchData() function is executing? Also be sure the data sent in $cookie is correct, that the passed data object was correctly received and extracting the value for $cookie works correctly.

    You might try calling the function directly from WP code instead of going through your API endpoint. If it works that way, the problem is farther back in your endpoint code.

    Thread Starter aniltonveiga

    (@aniltonveiga)

    Hello @bcworks, thank you for the quick response.
    The dispatchData function is being executed and I have passed all the data statically, but what happens is that the request does not exit the endpoint, I am using fiddler to map the external requests, if I put a try catch, it never goes into catch, but the request is not made, I tried the example using WP_Http :: post and even then the request is not made: /

    My code with your sugestion:

    	$url = 'https://mysistema.com.br/tracking/web-push';
    	$args=array(
    			'webPushId' => 'webpushteste2',
    			'source' => 'BLOG'
    	);
    
    	$defaults = array('method' => 'POST');
        $r = wp_parse_args( $args, $defaults );
    	return $this->request($url, $r);
    Moderator bcworkz

    (@bcworkz)

    I really cannot imagine any of those methods you’ve tried failing to work. How did you decide they all fail? Lack of response from mysistema.com? There is a lot that can still go wrong between sending a request and getting a response. I suspect the request is going out, but is failing at some point afterwards. That is unless you have hard evidence to the contrary.

    Hard evidence could come from a packet sniffer like tcpdump or wireshark. Unfortunately, your browser’s network developer tool doesn’t log these kind of requests, you need something that sits on the HTTP port and sniffs packet traffic. Using one of these tools, I think you will see the request going out. If that is the case, I don’t know how to track down the problem beyond WordPress, but at least you would know there wasn’t anything wrong with your code.

    How are you testing your code? A hosted web server, or a localhost installation? Whichever you are using, maybe you should try the other. If the other works, you then know it’s a problem unique to your current installation.

    Another possibility, are you sure you have the correct URL? A simple GET request with no data comes back 404. Maybe it’s the lack of data, but if that were the case, 404 is an inappropriate response. Not that servers don’t make inappropriate responses ?? It’s at least a little suspicious.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem using rest api’ is closed to new replies.