NetTalk Central

Author Topic: java.net.ProtocolException: Unexpected status line:  (Read 6701 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
java.net.ProtocolException: Unexpected status line:
« on: July 17, 2019, 03:27:49 PM »
Using NT server Im serving a page that is a simple xml to be parsed with a Basic4Android app.

The page is: http://132.148.84.1:8633/xmloc?F=Lanz&E=O-25-5-20

I can fetch it using Firefox
using Chrome I get ERR_INVALID_HTTP_RESPONSE
using android I get  java.net.ProtocolException: Unexpected status line:

What does Unexpected status line means?
What should I add to my page to be readable?
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: java.net.ProtocolException: Unexpected status line:
« Reply #1 on: July 17, 2019, 09:02:23 PM »
Hi Alberto,

Please, please, please tell me you are not planning to have an API service on an insecure connection? I'm hoping you'll say it'll definitely be secure, then I won't have to explode in your direction over your poor security habits...

Secondly, there's quite a lot wrong here. I presume you've "rolled your own" procedure here rather than using the NetWebServiceMethod? Alas if you have you've still got a few corrections to make.

Probably a good way for you to see what is going wrong is just to run the NetDemo app, WebClient procedure, and enter that URL you'll see the result from the server. Compare that to say https://www.capesoft.com/CapesoftAccessoriesRSSFeed.xml (or any response from a NetWebServiceMethod API).

You'll see your reply lacks the HTTP header, and at the same time includes a line at the top,
<!DOCTYPE html>
which has no meaning.

I hope this gets you going in the right direction...

cheers
Bruce




Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: java.net.ProtocolException: Unexpected status line:
« Reply #2 on: July 18, 2019, 04:54:02 AM »
Hi Bruce,
Please dont get mad on me... this is an internal software, I will make it secure ASAP, you will not have any problem fetching the page.

Ive rolled my own proc long before NetWebServiceMethod were realeased and now I cant change it, I need to make it work urgently.

I looked at the CapesoftAccessoriesRSSFeed.xml header and modify my proc to make a similar header but Chrome still says its wrong and I dont found the problem.

THis is the code Im using:

vLanza is a view.

Code: [Select]
        x.save(vLanza)   
        packet.Append(x.XmlData)
        packet.Replace('<?xml version="1.0" encoding="ISO-8859-1"?>','<?xml version="1.0" encoding="ISO-8859-1"?><13,10><lanz xmlns:lanz="http://www.armisoftware.com/xmloc" version="2.0">')
        packet.Append('</lanz>')

This code adds a header like your CapesoftAccessoriesRSSFeed.xml header

If you fetch again The page : http://132.148.84.1:8633/xmloc?F=Lanz&E=O-25-5-20

From java Im getting a Response Error. Unexpected status line: <?xml version="1.0" encoding="ISO-8859-1"?>

What am I doing wrong?
-----------
Regards
Alberto

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: java.net.ProtocolException: Unexpected status line:
« Reply #3 on: July 18, 2019, 06:56:21 AM »
Ive done it!

Adding...

        packet.Replace('<?xml version="1.0" encoding="ISO-8859-1"?>',|
            'HTTP/1.1 200 OK<13,10>Content-Length: '&packet.Length()&|
            '<13,10>Content-Type: text/xml<13,10><13,10><?xml version="1.0" encoding="ISO-8859-1"?>')

It is very important the 13,10 after the header.
-----------
Regards
Alberto