Skip to content

Instantly share code, notes, and snippets.

@pbasov
Last active December 20, 2015 08:08
Show Gist options
  • Save pbasov/6097861 to your computer and use it in GitHub Desktop.
Save pbasov/6097861 to your computer and use it in GitHub Desktop.

Revisions

  1. Paul Basov revised this gist Jul 28, 2013. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions solution.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    import requests
    from urllib3.filepost import encode_multipart_formdata
    r = requests.session()

    empinfo = {'color':'#000000','usr_id':'0',
    'login':'placeholder','password':'passw','password1':'passw',
    'sname':'surname','fname':'firstname','pname':'middlename',
    'bdate_dd':'01','bdate_mm':'01','bdate_yy':'1970',
    'ref_id':'0','dept':'','tasks':'',
    'phone_i':'','phone_e':'','email_e':'',
    'ho_text':'','sh_text':'',
    'pos':'position','res_id':'0',
    'sdate_dd':'01','sdate_mm':'07','sdate_yy':'2013',
    'alt':'','grp_id':'0','enable':'1'}

    #let's encode this shit ourselves
    fdata = encode_multipart_formdata(empinfo)

    prepped = requests.Request('POST', 'http://requestb.in/1dpgypo1', data=fdata[0]).prepare()
    prepped.headers['Content-Type'] = fdata[1]

    resp = r.send(prepped)
    print(resp.text)
  2. Paul Basov revised this gist Jul 28, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions request2.py
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@
    header = {'content-type':fdata[1]}

    r.post('hhttp://requestb.in/1dpgypo1?inspect', data=fdata[0], headers=header)
    #fdata[0] is a binary string

    #Result:http://requestb.in/1dpgypo1?inspect#sq02ui
    #Everything is cool, it would work, except the header has
  3. Paul Basov revised this gist Jul 28, 2013. 2 changed files with 9 additions and 9 deletions.
    10 changes: 5 additions & 5 deletions request1.py
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,8 @@

    r.post('http://requestb.in/1dpgypo1', files=empinfo)

    Result: http://requestb.in/1dpgypo1?inspect#1c2ogn
    Notice the unwanted filename and Content-Type statements.
    Content-Disposition: form-data; name="enable"; filename="enable"
    Content-Type: application/octet-stream
    ...
    #Result: http://requestb.in/1dpgypo1?inspect#1c2ogn
    #Notice the unwanted filename and Content-Type statements.
    #Content-Disposition: form-data; name="enable"; filename="enable"
    #Content-Type: application/octet-stream
    #...
    8 changes: 4 additions & 4 deletions request2.py
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@

    r.post('hhttp://requestb.in/1dpgypo1?inspect', data=fdata[0], headers=header)

    Result:http://requestb.in/1dpgypo1?inspect#sq02ui
    Everything is cool, it would work, except the header has
    Content-Type: application/x-www-form-urlencoded, multipart/form-data; boundary=....random
    And trying to set empty files={} doesn't work either, it still pushes application/x-www-form-urlencoded.
    #Result:http://requestb.in/1dpgypo1?inspect#sq02ui
    #Everything is cool, it would work, except the header has
    #Content-Type: application/x-www-form-urlencoded, multipart/form-data; boundary=....random
    #And trying to set empty files={} doesn't work either, it still pushes application/x-www-form-urlencoded.
  4. Paul Basov revised this gist Jul 28, 2013. 1 changed file with 25 additions and 0 deletions.
    25 changes: 25 additions & 0 deletions request2.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    import requests
    from urllib3.filepost import encode_multipart_formdata
    r = requests.session()

    empinfo = {'color':'#000000','usr_id':'0',
    'login':'placeholder','password':'passw','password1':'passw',
    'sname':'surname','fname':'firstname','pname':'middlename',
    'bdate_dd':'01','bdate_mm':'01','bdate_yy':'1970',
    'ref_id':'0','dept':'','tasks':'',
    'phone_i':'','phone_e':'','email_e':'',
    'ho_text':'','sh_text':'',
    'pos':'position','res_id':'0',
    'sdate_dd':'01','sdate_mm':'07','sdate_yy':'2013',
    'alt':'','grp_id':'0','enable':'1'}

    #let's encode this shit ourselves
    fdata = encode_multipart_formdata(empinfo)
    header = {'content-type':fdata[1]}

    r.post('hhttp://requestb.in/1dpgypo1?inspect', data=fdata[0], headers=header)

    Result:http://requestb.in/1dpgypo1?inspect#sq02ui
    Everything is cool, it would work, except the header has
    Content-Type: application/x-www-form-urlencoded, multipart/form-data; boundary=....random
    And trying to set empty files={} doesn't work either, it still pushes application/x-www-form-urlencoded.
  5. Paul Basov revised this gist Jul 28, 2013. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions request1.py
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@
    r.post('http://requestb.in/1dpgypo1', files=empinfo)

    Result: http://requestb.in/1dpgypo1?inspect#1c2ogn
    Notice the
    Notice the unwanted filename and Content-Type statements.
    Content-Disposition: form-data; name="enable"; filename="enable"
    Content-Type: application/octet-stream
    Content-Type: application/octet-stream
    ...
  6. Paul Basov created this gist Jul 28, 2013.
    20 changes: 20 additions & 0 deletions request1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    import requests
    r = requests.session()

    empinfo = {'color':'#000000','usr_id':'0',
    'login':'placeholder','password':'passw','password1':'passw',
    'sname':'surname','fname':'firstname','pname':'middlename',
    'bdate_dd':'01','bdate_mm':'01','bdate_yy':'1970',
    'ref_id':'0','dept':'','tasks':'',
    'phone_i':'','phone_e':'','email_e':'',
    'ho_text':'','sh_text':'',
    'pos':'position','res_id':'0',
    'sdate_dd':'01','sdate_mm':'07','sdate_yy':'2013',
    'alt':'','grp_id':'0','enable':'1'}

    r.post('http://requestb.in/1dpgypo1', files=empinfo)

    Result: http://requestb.in/1dpgypo1?inspect#1c2ogn
    Notice the
    Content-Disposition: form-data; name="enable"; filename="enable"
    Content-Type: application/octet-stream