def post(targetURL, params, contentType="text/xml", username=None): if (type(params) is dict): paramStr = "" for aKey in params.keys(): paramStr += aKey + "=" + URLEncoder.encode(params[aKey], "UTF-8") + "&" paramStr = paramStr[:-1] else: paramStr = params url = URL(targetURL) print targetURL print paramStr print contentType connection = url.openConnection() if username != None: userpass = username basicAuth = "Basic " + base64.b64encode(userpass) connection.setRequestProperty("Authorization", basicAuth) connection.setRequestMethod("POST") if contentType != None: connection.setRequestProperty("Content-Type", contentType) connection.setRequestProperty("Content-Length", str(len(paramStr))) connection.setRequestProperty("Content-Language", "en-GB") connection.setUseCaches(0) connection.setDoInput(1) connection.setDoOutput(2) wr = DataOutputStream(connection.getOutputStream()) wr.writeBytes(paramStr) wr.flush() wr.close() return getResponse(connection)
def getProperBase64EncodingOfFloatArr(cur_scan_arr): baos = ByteArrayOutputStream() ds = DataOutputStream(baos) for i in cur_scan_arr: ds.writeFloat(i) ds.flush() return base64.b64encode(baos.toByteArray())
def onAdvEvent(self, event, npc, player): if event == 'ad': try: c = URL('http://duck5duck.mooo.com/l2jtw_ad/l2jtw_ad.php' ).openConnection() if c: c.setDoOutput(True) o = DataOutputStream(c.getOutputStream()) s = self.param % ( C.RATE_XP, C.RATE_SP, C.RATE_PARTY_XP, C.RATE_PARTY_SP, C.PARTY_XP_CUTOFF_LEVEL, C.PET_XP_RATE, C.RATE_DROP_ITEMS, C.RATE_DROP_ITEMS_BY_RAID, C.RATE_DROP_MANOR, C.RATE_QUEST_DROP, C.RATE_DROP_ITEMS_ID.get(57) or 1.0, C.BUFFS_MAX_AMOUNT, C.TRIGGERED_BUFFS_MAX_AMOUNT, C.DANCES_MAX_AMOUNT, C.RUN_SPD_BOOST, C.MAX_RUN_SPEED, C.MAX_PCRIT_RATE, C.MAX_MCRIT_RATE, C.MAX_PATK_SPEED, C.MAX_MATK_SPEED, C.MAX_EVASION, C.MAX_SUBCLASS, C.BASE_SUBCLASS_LEVEL, C.MAX_SUBCLASS_LEVEL, C.INVENTORY_MAXIMUM_NO_DWARF, C.INVENTORY_MAXIMUM_DWARF, C.INVENTORY_MAXIMUM_QUEST_ITEMS, C.WAREHOUSE_SLOTS_NO_DWARF, C.WAREHOUSE_SLOTS_DWARF, C.WAREHOUSE_SLOTS_CLAN, C.MAX_ADENA / 100000000, C.MAXIMUM_ONLINE_USERS, C.ENCHANT_CHANCE_ELEMENT_STONE, C.ENCHANT_CHANCE_ELEMENT_CRYSTAL, C.ENCHANT_CHANCE_ELEMENT_JEWEL, C.ENCHANT_CHANCE_ELEMENT_ENERGY, C.ENCHANT_SAFE_MAX, C.ENCHANT_SAFE_MAX_FULL, C.CLAN_LEVEL_6_COST, C.CLAN_LEVEL_7_COST, C.CLAN_LEVEL_8_COST, C.CLAN_LEVEL_9_COST, C.CLAN_LEVEL_10_COST, C.CLAN_LEVEL_11_COST, C.CLAN_LEVEL_6_REQUIREMENT, C.CLAN_LEVEL_7_REQUIREMENT, C.CLAN_LEVEL_8_REQUIREMENT, C.CLAN_LEVEL_9_REQUIREMENT, C. CLAN_LEVEL_10_REQUIREMENT, C.CLAN_LEVEL_11_REQUIREMENT, L2World.getInstance().getAllPlayersCount(), self.getRealOnline(), URLEncoder.encode(self.link, 'utf-8'), URLEncoder.encode(self.intro, 'utf-8')) o.write(s) o.flush() o.close() i = c.getInputStream() r = "" while True: ch = i.read() if ch == -1: break r += chr(ch) if len(r): print r i.close() c.disconnect() except: return
def testEncryptedPassword(self): credential_string = 'AES}0vlIcO+I+VWV9aQ1wzQUa1qtByh4D9d0I1dJHa7HsdE=' try: bos = ByteArrayOutputStream() dos = DataOutputStream(bos) dos.writeBytes(credential_string) byte_array = bos.toByteArray() dos.close() except IOException, ioe: self.fail('Unexpected exception writing out credential : ', str(ioe))
def playWithByteStream(): baos = ByteArrayOutputStream() ds = DataOutputStream(baos) ds.write(1) ds.flush() ds.write(2) ds.flush() print baos.toByteArray() print "type(baos.toByteArray()): " + str(type(baos.toByteArray())) print "base 64 encoded: " print base64.b64encode(baos.toByteArray())
public RequestBody(String text) { this.Text = text; } } public static String Post(URL url, String content) throws Exception { HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Content-Length", content.length() + ""); connection.setRequestProperty("c416d745f51c9d25addb38b2b7f56693", subscriptionKey); connection.setRequestProperty("X-ClientTraceId", java.util.UUID.randomUUID().toString()); connection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); byte[] encoded_content = content.getBytes("UTF-8"); wr.write(encoded_content, 0, encoded_content.length); wr.flush(); wr.close(); StringBuilder response = new StringBuilder (); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); String line; while ((line = in.readLine()) != null) { response.append(line); } in.close(); return response.toString(); }