Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:01:36+00:00 2026-06-12T12:01:36+00:00

I’ve written some code to read and write articles on a MediaWiki server (specifically,

  • 0

I’ve written some code to read and write articles on a MediaWiki server (specifically, wikia.com). I’m able to get an edit token and read articles, no problem. But when I attempt to write an article, I get the following error:

java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.flushBuffer(AbstractSessionOutputBuffer.java:106)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.writeLine(AbstractSessionOutputBuffer.java:198)
at org.apache.http.impl.io.HttpRequestWriter.writeHeadLine(HttpRequestWriter.java:61)
at org.apache.http.impl.io.AbstractMessageWriter.write(AbstractMessageWriter.java:93)
at org.apache.http.impl.AbstractHttpClientConnection.sendRequestHeader(AbstractHttpClientConnection.java:240)
at org.apache.http.impl.conn.DefaultClientConnection.sendRequestHeader(DefaultClientConnection.java:252)
at org.apache.http.impl.conn.AbstractClientConnAdapter.sendRequestHeader(AbstractClientConnAdapter.java:227)
at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:213)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:483)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
at com.walkertribe.niftybot.wiki.MediaWiki.loadXML(MediaWiki.java:350)
... 3 more

Below is a simplified version of the code that attempts to write the article. I’m using Apache HttpClient for making requests against the server. The Page class is a POJO that, among other things, provides the title and last revision time of the article. The URIBuilder class is a convenience class for building URLs.

public void savePage(Page page, String content, String summary) {
    if (_token == null) {
        throw new IllegalStateException("No edit token received");
    }

    String md5;

    try {
        md5 = Util.md5(content);
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
        throw new RuntimeException(ex);
    }

    URIBuilder b = _config.buildURIBuilder()
            .addQueryParam("title", page.getTitle())
            .addQueryParam("text", content)
            .addQueryParam("summary", summary)
            .addQueryParam("bot", null)
            .addQueryParam("basetimestamp", page.getLastRevision())
            .addQueryParam("watchlist", "nochange")
            .addQueryParam("md5", md5)
            .addQueryParam("token", _token)
            .addQueryParam("starttimestamp", _timestamp);
    URI uri = b.toURI();
    Document doc = loadXML(uri, HttpMethod.POST);
    /* do stuff with the returned document */
}

private Document loadXML(URI uri, HttpMethod method) throws WikiException {
    HttpRequestBase requestBase = method.getMethod(uri);
    HttpResponse response;

    try {
        response = client.execute(requestBase);
    } catch (ClientProtocolException ex | IOException ex) {
        throw new WikiException(ex);
    }

    HttpEntity entity = response.getEntity();

    if (entity == null) {
        throw new WikiException("No content found: " + uri);
    }

    try (InputStream content = entity.getContent()) {
        // do something with the content
    } catch (IllegalStateException | IOException ex) {
        throw new WikiException(ex);
    }

    return doc;
}

private enum HttpMethod {
    GET {
        @Override
        public HttpRequestBase getMethod(URI uri) {
            return new HttpGet(uri);
        }
    },
    POST {
        @Override
        public HttpRequestBase getMethod(URI uri) {
            return new HttpPost(uri);
        }
    };

    abstract HttpRequestBase getMethod(URI uri); 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:01:39+00:00Added an answer on June 12, 2026 at 12:01 pm

    Figured it out. When the submitted text is large, you have to use a MultipartEntity for the post operation. Given a NameValuePair list of parameters named params and the URI to post to:

    HttpPost post = new HttpPost(uri);
    MultipartEntity entity = new MultipartEntity();
    
    for (NameValuePair param : params) {
        entity.addPart(param.getName(), new StringBody(param.getValue()));
    }
    
    post.setEntity(entity);
    
    try {
        HttpResponse response = client.execute(post);
        // do something with the response
    } catch (ClientProtocolException ex | IOException ex) {
        // deal with exception
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.