I am using the following code to get information from my server where uuid is a machine id;

void validateSerial( const String &sn, const String &sku )
URL url( “https://website.com” );
url = url.withParameter( “wc-api”, “validate_serial_key” );
url = url.withParameter( “serial”, sn );
url = url.withParameter( “sku”, sku );
url = url.withParameter( “uuid”, uuidStr );

ScopedPointer is = url.createInputStream( false );

On a few machines mac and pc, maybe one out of a a hundred, url.createInputStream is returning nullPtr;

Is there a better method of doing this or why would a few machines return nullPtr

From the docs:

Returns an input stream that the caller must delete, or a null pointer if there was an error trying to open it.

Maybe try to evaluate the http status code:

int status;
if (ScopedPointeryImputStream> is = url.createInputStream( false,
    nullptr /* progressCallback */,
    nullptr /* progressCallbackContext */,
    String() /*extraHeaders  */,
    0 /* connectionTimeOutMs */,
    nullptr /* responseHeaders */,
    &status /* statusCode */) )
    // do your stuff
} else {
    DBG ("Http error: " + String (status));

That should tell you more…

Thanks, but I am not on my customers machines so I can’t see the status.
Weird, that I have several machines here and there is no error on any of them.

I was hoping to avoid using a customer as a tester, but I guess there is no other alternative.
I’ll report back with the error in a while.

Yes, it always pays off to present usefull error messages to the users :wink:

OK it returns a status code of 0, immediately.

That is not an https status code, correct?

What now?

You win :wink:
I have no idea. Digging into the sources tells me, that WebInputStream has no common implementation but is implemented in each platform differently, e.g. mac:

So I think createConnection failed (see line 615).

In line 406 you find the condition for URLConnectionState::start() to fail:

And if you follow that trail you end up deep in ObjectiveC code I don’t dare to interpret.
So maybe someone else can give you a more qualified answer…

99% of the cases, when createInputStream retuns nullptr it means that there was a connection error. Probably the customers have their firewalls on or their internet connection is intermittent.

1 Like

Well their firewalls are turned off and the antivirus stuff is turned off.

That was the first thing I asked of them.

Is there another juce method of sending the request?

If not I’ll have to use something like cURL. Oouch!

Well you can make JUCE use curl by setting JUCE_USE_CURL in the Projucer and shuffling around a few include files in the JUCE/modules/juce_core/juce_core.cpp. Here is a patch:

 diff --git a/modules/juce_core/juce_core.cpp b/modules/juce_core/juce_core.cpp
 index 370e7d7..d1ac894 100644
 --- a/modules/juce_core/juce_core.cpp
 +++ b/modules/juce_core/juce_core.cpp
 @@ -45,6 +45,10 @@
  #include <cctype>
  #include <cstdarg>
 +#include <curl/curl.h>
   #include <sys/timeb.h>
   #include <cwctype>
 @@ -87,9 +91,6 @@
    #include <ifaddrs.h>
    #include <sys/resource.h>
 -   #include <curl/curl.h>
 -  #endif
   #include <pwd.h>
 @@ -185,6 +186,10 @@ namespace juce
  #include "zip/juce_ZipFile.cpp"
  #include "files/juce_FileFilter.cpp"
  #include "files/juce_WildcardFileFilter.cpp"
 + #include "native/juce_curl_Network.cpp"
 @@ -199,7 +204,7 @@ namespace juce
  #include "native/juce_mac_Files.mm"
 -#include "native/juce_mac_Network.mm"
 +//#include "native/juce_mac_Network.mm"
  #include "native/juce_mac_Strings.mm"
  #include "native/juce_mac_SystemStats.mm"
  #include "native/juce_mac_Threads.mm"
 @@ -217,9 +222,6 @@ namespace juce
  #include "native/juce_linux_CommonFile.cpp"
  #include "native/juce_linux_Files.cpp"
  #include "native/juce_linux_Network.cpp"
      - #include "native/juce_curl_Network.cpp"
  #include "native/juce_linux_SystemStats.cpp"
 #include "native/juce_linux_Threads.cpp"

You’ll also need to link to libcurl: