Note that there are some explanatory texts on larger screens.

plurals
  1. PO403 error while fetching content from URL
    text
    copied!<p>I am trying to automate a process. For that I need to fetch XML by hitting a URL, multiple times in 1 run, and then parse it. For 1 run of the program, the URL could be hit anywhere between 4 to 25 times. This all seems fine until a 403 error response is returned.</p> <p>Interestingly, the 403 always comes up for every 5th or 6th time the URL is hit.</p> <p>I am using JDOM to parse the XML response.</p> <p>I have tried the codes:</p> <pre><code>Document doc = builder.build(new InputSource(url.openStream())); </code></pre> <p>and </p> <pre><code>HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)"); Document doc = builder.build(conn.getInputStream()); </code></pre> <p>With the second one I get the Exception:</p> <pre><code>org.jdom.input.JDOMParseException: Error on line 1: White spaces are required between publicId and systemId. </code></pre> <p>Could someone please help me in getting rid of the 403. Please note that I do not have any control over the source if a change is required to be made as talked about <a href="http://www.sugarcrm.com/forums/f6/white-spaces-required-between-publicid-systemid-12367/" rel="nofollow noreferrer">here</a></p> <p>Also, I am not sure if <a href="https://stackoverflow.com/questions/4633048/httpurlconnection-reading-response-content-on-403-error">this link</a> is helpful.</p> <p>Thank you.</p> <p><hr/> [UPDATE 1]: This is somehow working, without having to <code>sleep</code>: </p> <pre><code>try{ doc = builder.build(conn.getInputStream()); }catch(IOException ioEx){ doc = builder.build(new InputSource(url.openStream())); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload