Perhaps you can try to print the url to console or maybe just the length to see how long it is? Perhaps you are exceeding some kind of buffer length somewhere.. You could also experiment by adding "&status=xxx" then gradually increasing the length until you trigger the error.
Maybe you could also add a delay between the write and the isdataEmpty() to make sure there is no timing problem.