vb6 login to website winhttp with my code here - vb6

please someone kindly review this code and help me fix it so i can login. i am unable to login.
if i login via firefox and capture the packets and use that login cookie in this winhttp then this code loggs in ok. i just need to know how to get the cookie to work with my code
Text1.Text = ""
Text13.Text = ""
Dim httpReq As New WinHttp.WinHttpRequest
Dim strLineOut As String
Dim strReturn As String
Dim strStatus As String
strLineOut = "username=laxom47743#5k2u.com&password=test12312&credentialId="
''httpReq.Open "POST", "https://accounts.zerotier.com//auth/realms/zerotier/login-actions/authenticate?session_code=o8twzbdn6KXGaRi27fyZDwH1pwuHfQlcYn-0AhzpPgc&execution=86f116b6-9ab4-4790-acb0-bb7ac9eb98d0&client_id=zt-central&tab_id=zciqEAPtfYI", False
httpReq.Open "POST", "https://accounts.zerotier.com/auth/realms/zerotier/login-actions/authenticate?session_code=" & Text4.Text & "execution=" & Text6.Text & "&client_id=" & Text9.Text & "&tab_id=" & Text10.Text, False
httpReq.SetRequestHeader "Host", " accounts.zerotier.com"
httpReq.SetRequestHeader "User-Agent", Text12.Text
httpReq.SetRequestHeader "Accept", " text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"
httpReq.SetRequestHeader "Accept-Language", " en-GB,en;q=0.5"
httpReq.SetRequestHeader "Accept-Encoding", " gzip, deflate, br"
httpReq.SetRequestHeader "Content-Type", " application/x-www-form-urlencoded"
httpReq.SetRequestHeader "Content-Length", " 50"
httpReq.SetRequestHeader "Origin", " null"
httpReq.SetRequestHeader "Connection", " keep-alive"
'httpReq.SetRequestHeader "Cookie", " AUTH_SESSION_ID=" & Text9.Text & ".ztc-keycloak-2; AUTH_SESSION_ID_LEGACY=" & Text9.Text & ".ztc-keycloak-2; KC_RESTART=eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJkNjhjZTJjZS01ZThjLTRhNjMtYjllOS05NzljZGU3YmQwNzkifQ.eyJjaWQiOiJ6dC1jZW50cmFsIiwicHR5Ijoib3BlbmlkLWNvbm5lY3QiLCJydXJpIjoiaHR0cHM6Ly9teS56ZXJvdGllci5jb20vYXBpL19hdXRoL29pZGMvY2FsbGJhY2siLCJhY3QiOiJBVVRIRU5USUNBVEUiLCJub3RlcyI6eyJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIiwiaXNzIjoiaHR0cHM6Ly9hY2NvdW50cy56ZXJvdGllci5jb20vYXV0aC9yZWFsbXMvemVyb3RpZXIiLCJyZXNwb25zZV90eXBlIjoiY29kZSIsInJlZGlyZWN0X3VyaSI6Imh0dHBzOi8vbXkuemVyb3RpZXIuY29tL2FwaS9fYXV0aC9vaWRjL2NhbGxiYWNrIiwic3RhdGUiOiJzdGF0ZSJ9fQ.C4ENxi3c4OxqOlfebggr2H7IJDYrTqLd19Y2WmsanDQ"
httpReq.SetRequestHeader "Cookie", " AUTH_SESSION_ID=2a9ac060-678f-4bba-9b9c-5090f644ba6b.ztc-keycloak-1; AUTH_SESSION_ID_LEGACY=2a9ac060-678f-4bba-9b9c-5090f644ba6b.ztc-keycloak-1; KC_RESTART=eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJkNjhjZTJjZS01ZThjLTRhNjMtYjllOS05NzljZGU3YmQwNzkifQ.eyJjaWQiOiJ6dC1jZW50cmFsIiwicHR5Ijoib3BlbmlkLWNvbm5lY3QiLCJydXJpIjoiaHR0cHM6Ly9teS56ZXJvdGllci5jb20vYXBpL19hdXRoL29pZGMvY2FsbGJhY2siLCJhY3QiOiJBVVRIRU5USUNBVEUiLCJub3RlcyI6eyJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIiwiaXNzIjoiaHR0cHM6Ly9hY2NvdW50cy56ZXJvdGllci5jb20vYXV0aC9yZWFsbXMvemVyb3RpZXIiLCJyZXNwb25zZV90eXBlIjoiY29kZSIsInJlZGlyZWN0X3VyaSI6Imh0dHBzOi8vbXkuemVyb3RpZXIuY29tL2FwaS9fYXV0aC9vaWRjL2NhbGxiYWNrIiwic3RhdGUiOiJzdGF0ZSJ9fQ.C4ENxi3c4OxqOlfebggr2H7IJDYrTqLd19Y2WmsanDQ"
httpReq.SetRequestHeader "Upgrade-Insecure-Requests", " 1"
httpReq.SetRequestHeader "Sec-Fetch-Dest", " document"
httpReq.SetRequestHeader "Sec-Fetch-Mode", " navigate"
httpReq.SetRequestHeader "Sec-Fetch-Site", " same-origin"
httpReq.SetRequestHeader "Sec-Fetch-User", " ?1"
Text1.Text = Text1.Text & httpReq.ResponseText
Text13.Text = Text13.Text & httpReq.GetAllResponseHeaders
' signed-in
If InStr(httpReq.ResponseText, "Your Networks") Then
Debug.Print "Your Networks"
End If
Set httpReq = Nothing

Related

Encoding problem when sending a request using RestTemplate

Sending a request using RestTemplate
var emailDto = new EmailDto();
email.setBody(DATA_TEXT);
HttpHeaders headers = new HttpHeaders();
Charset utf8 = Charset.forName("UTF-8");
MediaType mediaType = new MediaType("text", "html", utf8);
headers.setContentType(mediaType);
var httpEntity = new HttpEntity<>(emailDto , headers);
//restTemplate.getMessageConverters()
// .add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
var response = restTemplate.exchange(
ResponseEntity<String> response= restTemplate.exchange(
emailPath,
HttpMethod.POST,
httpEntity,
String.class);
DATA_TEXT - here is a piece of html code that I'm trying to send in a request
public static final String DATA_TEXT =
"<body style='margin:0;padding:0;'> " +
"<table role='table' style='width:100%%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;'> " +
"<tr> <td align='center' style='padding:0;'> " +
"<table role='table' style='width:602px;border-collapse:collapse;border:1px solid #cccccc;border-spacing:0;text-align:left;'> " +
"<tr> <td align='center' style='padding:4px 0 4px;background:#FFFFFF;border:1px solid #cccccc;'> " +
"<img src='https://i.logo.co/redfggq7/logo.png' alt='my_logo' width='170' " +
"</td></tr><tr> <td style='padding:36px 30px 42px 30px;background:#F0F4F2;font-family:Roboto,sans-serif;'> " +
"<p style='font-family: Roboto, sans-serif;'>Текст авпвапва вар о пор ораоа про прп" +
"</p><p style='font-family: Roboto, sans-serif;'>" +
"</p>" +
"</td></tr><tr> <td style='padding:30px;background:#198754;text-align:center;border:1px solid #cccccc;'> " +
"<a style='text-decoration:none;color:#ffffff;opacity:50%%' href='#'>my.com</a> " +
"</td></tr></table></td></tr></table> </body>";
When sending a request, it returns the following error:
org.springframework.web.client.RestClientException: No HttpMessageConverter for ru.ocpiouserbacktest.model.EmailDto and content type "text/html;charset=UTF-8"
In the file Pom.xml specified
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
With this:
MediaType mediaType = new MediaType("text", "html", utf8);
headers.setContentType(mediaType);
You're telling Spring that the content of your payload will be text/html.
However, with this:
var httpEntity = new HttpEntity<>(emailDto , headers);
You're telling Spring to send an EmailDto object - which understandably Spring has no idea how to convert to text/html and Spring won't know that EmailDto happens to contain a field with HTML in it.

How is possible that Spring cache return modified object?

i have this test:
#Test
public void testCacheLineOfCredit() throws Exception {
LineOfCreditInfo created = repository.save(this.getInfo());
assertThat(created, is(notNullValue()));
//First fetch read from DB
LineOfCreditInfo firstSearch = service.fetch(created.getId());
System.out.println("Created ID: " + created.getId() + " Date: " + created.getStartDate().toString());
System.out.println("First ID: " + firstSearch.getId() + " Date: " + firstSearch.getStartDate().toString());
assertEquals(created.getStartDate(), firstSearch.getStartDate());
Thread.sleep(100);
LineOfCreditInfo updated = this.getInfo();
updated.setId(created.getId());
updated.setAgreement(created.getAgreement());
repository.save(updated);
//Second fetch read from cache
LineOfCreditInfo secondSearch = service.fetch(created.getId());
System.out.println("---------------------------------------");
System.out.println("Updated ID: " + created.getId() + " Date: " + created.getStartDate().toString());
System.out.println("Second ID: " + secondSearch.getId() + " Date: " + secondSearch.getStartDate().toString());
}
Well the output of the System.out is this:
Object read from database
Created ID: c7e635c6-6024-4149-9f92-74316c149800 Date: 2020-02-25T16:22:01.181+01:00[Europe/Berlin]
First ID: c7e635c6-6024-4149-9f92-74316c149800 Date: 2020-02-25T16:22:01.181+01:00[Europe/Berlin]
---------------------------------------
Updated ID: c7e635c6-6024-4149-9f92-74316c149800 Date: 2020-02-25T16:22:01.464+01:00[Europe/Berlin]
Second ID: c7e635c6-6024-4149-9f92-74316c149800 Date: 2020-02-25T16:22:01.464+01:00[Europe/Berlin]
How is possible that the second Id Date is equal at the updated object if this is read from cache?
In the service there's a system.out that write only in the first fetch, correctly.
This is the service method:
#Cacheable(value = "lineOfCredits")
public LineOfCreditInfo fetch(String id) throws ContextOutOfDomainException {
InvoiceFinancingContext context = contextFactory.getObject();
log.info(String.format("Object read from database: Id[%s]", id));
Optional<LineOfCreditInfo> lineOfCreditInfo = repository.findByIdAndDomainId(id, context.getDomainId());
System.out.println("Object read from database");
return lineOfCreditInfo.get();
}
I think you tried to print here the "updated" object :
System.out.println("Updated ID: " + updated.getId() + " Date: " + updated.getStartDate().toString());
And not the "created" in the "Updated ID" like your current code :
System.out.println("Updated ID: " + created.getId() + " Date: " + created.getStartDate().toString());

How to send several String to Spring?

How it's possible to send several string to spring? If I convert several Strings to the Array, I can send, but if I try to send several Strings it's not working. Send Array to Spring not good idea, becouse in Spring I will must use more code (split , new String, etc.)
function sendCustomerInfo() {
var nameCustomerForSend = $("#NickNameCustomerForSend").val();
var phoneCustomerForSend = $("#PhoneCustomerForSend").val();
var emailCustomerForSend = $("#EmailCustomerForSend").val();
var addressCustomerForSend = $("#descriptionCustomerForSend").val();
console.log("Name: " + nameCustomerForSend + " Address: " + addressCustomerForSend + " Phone: " + phoneCustomerForSend
+ " Email: " + emailCustomerForSend);
$.ajax({
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
type: "POST", //это типа method
data: {NickName:nameCustomerForSend, Phone:phoneCustomerForSend, Email:emailCustomerForSend,
description:addressCustomerForSend},
url: '/showAll/customerInfo',
success: function (msg) {
window.location.href = "/showAll"
}
});
}
I receive: Failed to load resource: the server responded with a status of 401 ()
In Spring I try to receive:
#RequestMapping(value = "/showAll/customerInfo", method = { RequestMethod.POST}
, produces = MediaType.APPLICATION_JSON_VALUE)
public ModelAndView showAllForCustomer(#RequestParam(value = "NickName")String name,
#RequestParam(value = "Phone")String phone,
#RequestParam(value = "description")String addressDelivery,
#RequestParam(value = "Email")String email) {
System.out.println("Name: " + name + " Phone: " + phone + " Address: " + addressDelivery + " Email: " + email);
ModelAndView modelAndView = new ModelAndView();
return modelAndView;
}
Use #RequestBody with post and application/json type data
Create DTO having all parameter as you specified in showAllForCustomer
like
public ModelAndView showAllForCustomer(#RequestBody CustomerDto dto){
............
}

How to call WCF Service Method in VB6.0 Application

I want to call WCF Service Method(with parameter) in my VB6.0 Apllication.The URL of my WCF Service is :-HTTP://10.1.1.169:7794/ and method which I want to call is ConvertXMLDataToDBFAndAccess and there are four parameters which is using by this method.The Parameters are:-xmldata,isCompressed,AccessFileName,DBFFileName.
Currently I have no code related to service.So without any changes in service code Can you provide me code in visual basic 6.0.This Service running in another computer and my machine is in same network so that's why I am able to access the service
I hope this helps...
Dim strSoap, strSOAPAction As String
Dim strURL As String ' WEB SERVICE URL
Dim DataToSend as String
strSoap = "<?xml version=""1.0"" encoding=""utf-8""?><s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<s:Body>" & _
"<YOURMethodName xmlns=""http://tempuri.org/"">" & _
"<YOURMethodParameterName>DataToSend</YOURMethodParameterName>" & _
"</YOURMethodName>" & _
"</s:Body></s:Envelope>"
'REPLACE WITH YOUR DATA
strSOAPAction = "http://tempuri.org/YOURContractName/YOURMethodName" ' REPLACE HERE
Dim xmlhttp As MSXML2.XMLHTTP30
Set xmlhttp = New MSXML2.XMLHTTP30
xmlhttp.open "POST", strURL, False 'HERE YOU OPEN THE CONECTION WITH THE WebService
xmlhttp.setRequestHeader "Man", "POST " & strURL & " HTTP/1.1" ' DEFINE THE COMUNICATION TYPE
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 'DEFINE CONTENT TYPE
xmlhttp.setRequestHeader "SOAPAction", strSOAPAction ' ASSOCIATE THE SOAP ACTION
DoEvents
Call xmlhttp.send(strSoap) ' SEND THE REQUEST
DoEvents
If xmlhttp.Status = 200 Then
' IT WORKED
Else
'ERROR
End If
Dim strSoap, strSOAPAction As String
Dim strURL As String ' WEB SERVICE URL
Dim DataToSend As String
DataToSend = "demo.mdb"
strURL = "10.4.5.169:7794"
strSoap = "<?xml version=""1.0"" encoding=""utf-8""?><s:Envelopexmlns:s=""http://schemas.xmlsoap.org/wsdl/soap/envelope/"">" & _
"<s:Body>" & _
"<MoveFile xmlns=""http://tempuri.org/"">" & _
"<fileName>DataToSend</fileName>" & _
"</MoveFile>" & _
"</s:Body></s:Envelope>"
'REPLACE WITH YOUR DATA
strSOAPAction = "http://tempuri.org/DemoConnect/MoveFile" ' REPLACE HERE
Dim xmlhttp As MSXML2.XMLHTTP30
Set xmlhttp = New MSXML2.XMLHTTP30
xmlhttp.Open "POST", strURL, False
xmlhttp.setRequestHeader "Man", "POST " & strURL & " HTTP/1.1"
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "SOAPAction", strSOAPAction
xmlhttp.send (strSoap)
here MoveFile is method name and fileName is parameter name

Run workflow from ribbon button

I was trying to run a workflow from ribbon button in grid:
function TriggerWorkflow(entityId, workflowGuid)
{
debugger;
/*Generate Soap Body.*/
var soapBody = "<soap:Body>" +
" <Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
" <Request xsi:type=\'ExecuteWorkflowRequest\'>" +
" <EntityId>" + entityId + "</EntityId>" +
" <WorkflowId>" + workflowGuid + "</WorkflowId>" +
" </Request>" +
" </Execute>" +
"</soap:Body>";
/*Wrap the Soap Body in a soap:Envelope.*/
var soapXml = "<soap:Envelope " +
" xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' " +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
GenerateAuthenticationHeader() +
soapBody +
"</soap:Envelope>";
/* Create the XMLHTTP object for the execute method.*/
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", "/MSCRMservices/2007/crmservice.asmx", false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
/* Send the XMLHTTP object. */
xmlhttp.send(soapXml);
}
But it did throw an exception:
GenerateAuthenticationHeader() is undefined
Instead of using the GenerateAuthenticationHeader(), try using the following code:
var context = GetGlobalContext();
var header = context.getAuthenticationHeader();
Or if it doesn't work, create the authentication header manually
<soap:Header>
<CrmAuthenticationToken xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
<AuthenticationType xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
0
</AuthenticationType>
<OrganizationName xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
AdventureWorksCycle
</OrganizationName>
<CallerId xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
00000000-0000-0000-0000-000000000000
</CallerId>
</CrmAuthenticationToken>
</soap:Header>

Resources