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 7159703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:16:30+00:00 2026-05-28T13:16:30+00:00

I wrote a simple HTTP client and server in Python for experimenting. The first

  • 0

I wrote a simple HTTP client and server in Python for experimenting. The first code snippet below shows how I send an HTTP GET request with a parameter named imsi. In the second code snippet I show my do_Get function implementation in the server side. My question is how I can extract the imsi parameter in the server code and send a response back to the client in order to signal the client that imsi is valid.
Thanks.

P.S.: I verified that the client sends the request successfully.

CLIENT code snippet

    params = urllib.urlencode({'imsi': str(imsi)})
    conn = httplib.HTTPConnection(host + ':' + str(port))
    #conn.set_debuglevel(1)
    conn.request("GET", "/index.htm", 'imsi=' + str(imsi))
    r = conn.getresponse()

SERVER code snippet

import sys, string, cStringIO, cgi, time, datetime
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer

class MyHandler(BaseHTTPRequestHandler):

# I want to extract the imsi parameter here and send a success response to 
# back to the client.
def do_GET(self):
    try:
        if self.path.endswith(".html"):
            #self.path has /index.htm
            f = open(curdir + sep + self.path)
            self.send_response(200)
            self.send_header('Content-type','text/html')
            self.end_headers()
            self.wfile.write("<h1>Device Static Content</h1>")
            self.wfile.write(f.read())
            f.close()
            return
        if self.path.endswith(".esp"):   #our dynamic content
            self.send_response(200)
            self.send_header('Content-type','text/html')
            self.end_headers()
            self.wfile.write("<h1>Dynamic Dynamic Content</h1>")
            self.wfile.write("Today is the " + str(time.localtime()[7]))
            self.wfile.write(" day in the year " + str(time.localtime()[0]))
            return

        # The root
        self.send_response(200)
        self.send_header('Content-type','text/html')
        self.end_headers()

        lst = list(sys.argv[1])
        n = lst[len(lst) - 1]
        now = datetime.datetime.now()

        output = cStringIO.StringIO()
        output.write("<html><head>")
        output.write("<style type=\"text/css\">")
        output.write("h1 {color:blue;}")
        output.write("h2 {color:red;}")
        output.write("</style>")
        output.write("<h1>Device #" + n + " Root Content</h1>")
        output.write("<h2>Device Addr: " + sys.argv[1] + ":" + sys.argv[2] + "</h1>")
        output.write("<h2>Device Time: " + now.strftime("%Y-%m-%d %H:%M:%S") + "</h2>")
        output.write("</body>")
        output.write("</html>")

        self.wfile.write(output.getvalue())

        return

    except IOError:
        self.send_error(404,'File Not Found: %s' % self.path)
  • 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-05-28T13:16:30+00:00Added an answer on May 28, 2026 at 1:16 pm

    You can parse the query of a GET request using urlparse, then split the query string.

    from urlparse import urlparse
    query = urlparse(self.path).query
    query_components = dict(qc.split("=") for qc in query.split("&"))
    imsi = query_components["imsi"]
    # query_components = { "imsi" : "Hello" }
    
    # Or use the parse_qs method
    from urlparse import urlparse, parse_qs
    query_components = parse_qs(urlparse(self.path).query)
    imsi = query_components["imsi"] 
    # query_components = { "imsi" : ["Hello"] }
    

    You can confirm this by using

     curl http://your.host/?imsi=Hello
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple http server as part of my project. Below is
I wrote two simple programs server and a client using sockets in C++ (Linux).
I want to write a simple SSL HTTP client in Python and have heard
I am creating a simple HTTP client/server application on my local machine but I
A former developer wrote or client-server api in PHP. It simply sends messages as
I've had this REST Server (written by myself) that is secured by simple HTTP
I am writing a simple client-server application, and looking the MSDN docs, I came
I am connecting to tomcat over JMX. I wrote a simple JMX client to
I'm writing my first client/server android app, and need an advice regarding server architecture.
I'm using HTTP::Server::Simple::CGI to write a simple webserver. Within my handler, I have to

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.