Maven shade plugin

If you are using Maven to your Java project and you want to build with dependencies, add this to pom.xml to build:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <shadedClassifierName>shaded</shadedClassifierName>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <shadedClassifierName></shadedClassifierName>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>vn.com.ducnt.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
Advertisements

Send POST request with python using urllib2

Source code:

import httplib
import urllib
import urllib2

urllib2.install_opener(
    urllib2.build_opener(
        urllib2.ProxyHandler({'http': '127.0.0.1:8080'})
    )
)

headers = {
    #'Host': 'host.com',
    #'Connection': 'keep-alive',
    #'Content-Length': '325', 
    #'Origin': 'https://digitalvita.pitt.edu',
    #'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1',
    'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    #'Accept': 'text/javascript, text/html, application/xml, text/xml, */*',
    #'Referer': 'https://digitalvita.pitt.edu/index.php',
    #'Accept-Encoding': 'gzip,deflate,sdch',
    #'Accept-Language': 'en-US,en;q=0.8',
    #'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
    #'Cookie': 'PHPSESSID=lvetilatpgs9okgrntk1nvn595'
}

data = urllib.urlencode({
    "username":"admin",
    "password":"admin"})
req = urllib2.Request('http://abc.def/path', data, headers)
response = urllib2.urlopen(req)
print response.read()